From 3c4f1543aaf955e96a526b4fe13688645e14e720 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Tue, 18 Jun 2013 12:15:54 +0200 Subject: [PATCH] Moving caret back to selected node when documentCanvas is shown again --- modules/documentCanvas/documentCanvas.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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); } }; -- 2.20.1