From: Aleksander Ɓukasz Date: Tue, 18 Jun 2013 10:15:54 +0000 (+0200) Subject: Moving caret back to selected node when documentCanvas is shown again X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/3c4f1543aaf955e96a526b4fe13688645e14e720?ds=sidebyside Moving caret back to selected node when documentCanvas is shown again --- diff --git a/modules/documentCanvas/documentCanvas.js b/modules/documentCanvas/documentCanvas.js index 2c31ce0..d8c199b 100644 --- a/modules/documentCanvas/documentCanvas.js +++ b/modules/documentCanvas/documentCanvas.js @@ -56,6 +56,8 @@ return function(sandbox) { if(!view.shownAlready) { view.shownAlready = true; view.selectFirstNode(); + } else if(view.currentNode) { + view.moveCarretToNode(view.getNodeElement(view.currentNode)); } }; @@ -165,12 +167,7 @@ return function(sandbox) { nodeElement.addClass('rng-module-documentCanvas-currentNode'); if(options.moveCarret) { - var range = document.createRange(); - range.selectNodeContents(nodeElement[0]); - range.collapse(false); - var selection = document.getSelection(); - selection.removeAllRanges() - selection.addRange(range); + this.moveCarretToNode(nodeElement); } this.currentNode = wlxmlNode; @@ -212,6 +209,14 @@ return function(sandbox) { }, getNodeElement: function(wlxmlNode) { return this.node.find('#'+wlxmlNode.id); + }, + moveCarretToNode: function(nodeElement) { + var range = document.createRange(); + range.selectNodeContents(nodeElement[0]); + range.collapse(false); + var selection = document.getSelection(); + selection.removeAllRanges() + selection.addRange(range); } };