Moving caret back to selected node when documentCanvas is shown again
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 18 Jun 2013 10:15:54 +0000 (12:15 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 18 Jun 2013 10:15:54 +0000 (12:15 +0200)
modules/documentCanvas/documentCanvas.js

index 2c31ce0..d8c199b 100644 (file)
@@ -56,6 +56,8 @@ return function(sandbox) {
                 if(!view.shownAlready) {\r
                     view.shownAlready = true;\r
                     view.selectFirstNode();\r
+                } else if(view.currentNode) {\r
+                    view.moveCarretToNode(view.getNodeElement(view.currentNode));\r
                 }\r
             };\r
                       \r
@@ -165,12 +167,7 @@ return function(sandbox) {
             nodeElement.addClass('rng-module-documentCanvas-currentNode');\r
              \r
             if(options.moveCarret) {\r
-                var range = document.createRange();\r
-                range.selectNodeContents(nodeElement[0]);\r
-                range.collapse(false);\r
-                var selection = document.getSelection();\r
-                selection.removeAllRanges()\r
-                selection.addRange(range);\r
+                this.moveCarretToNode(nodeElement);\r
             }\r
             \r
             this.currentNode = wlxmlNode;\r
@@ -212,6 +209,14 @@ return function(sandbox) {
         },\r
         getNodeElement: function(wlxmlNode) {\r
             return this.node.find('#'+wlxmlNode.id);\r
+        },\r
+        moveCarretToNode: function(nodeElement) {\r
+            var range = document.createRange();\r
+            range.selectNodeContents(nodeElement[0]);\r
+            range.collapse(false);\r
+            var selection = document.getSelection();\r
+            selection.removeAllRanges()\r
+            selection.addRange(range);\r
         }\r
     };\r
     \r