From: Aleksander Ɓukasz Date: Mon, 12 May 2014 13:27:38 +0000 (+0200) Subject: canvas: handle RangeFragments returned from actions - first simplistic take X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/fb1b343bcfc05dbdd9f5d4d2d6ad9f243bb21300?hp=94e78db871e2d12a5698fced12f656dac563869f canvas: handle RangeFragments returned from actions - first simplistic take This should be expanded to actually make a selection. --- diff --git a/src/editor/modules/documentCanvas/documentCanvas.js b/src/editor/modules/documentCanvas/documentCanvas.js index 5942d8f..98c09d2 100644 --- a/src/editor/modules/documentCanvas/documentCanvas.js +++ b/src/editor/modules/documentCanvas/documentCanvas.js @@ -82,12 +82,18 @@ return function(sandbox) { canvas.setCurrentElement(node); }, onAfterActionExecuted: function(action, ret) { - if(ret && ret.isValid() && ret instanceof canvas.wlxmlDocument.NodeFragment) { + if(ret && ret.isValid()) { logger.debug('The action returned a valid fragment'); - var params = { - caretTo: ret instanceof canvas.wlxmlDocument.CaretFragment ? ret.offset : 'start' - }; - canvas.setCurrentElement(ret.node, params); + if(ret instanceof canvas.wlxmlDocument.RangeFragment) { + canvas.setCurrentElement(ret.endNode, {caretTo: ret.endOffset}); + } else if(ret instanceof canvas.wlxmlDocument.NodeFragment) { + var params = { + caretTo: ret instanceof canvas.wlxmlDocument.CaretFragment ? ret.offset : 'start' + }; + canvas.setCurrentElement(ret.node, params); + } else { + logger.debug('Fragment not supported'); + } return; } logger.debug('No valid fragment returned from the action');