Visual editor - inserting node before the current one if anchorOffset is 0
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Sun, 5 May 2013 19:46:55 +0000 (21:46 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Sun, 5 May 2013 19:46:55 +0000 (21:46 +0200)
modules/visualEditor.js

index 17e7f73..012f7a9 100644 (file)
@@ -98,6 +98,7 @@ rng.modules.visualEditor = function(sandbox) {
         insertNewNode: function(wlxmlTag, wlxmlClass) {\r
             //TODO: Insert inline\r
             var anchor = $(window.getSelection().anchorNode);\r
         insertNewNode: function(wlxmlTag, wlxmlClass) {\r
             //TODO: Insert inline\r
             var anchor = $(window.getSelection().anchorNode);\r
+            var anchorOffset = window.getSelection().anchorOffset;\r
             if(anchor[0].nodeType === Node.TEXT_NODE)\r
                 anchor = anchor.parent();\r
             if(anchor.text() === '') {\r
             if(anchor[0].nodeType === Node.TEXT_NODE)\r
                 anchor = anchor.parent();\r
             if(anchor.text() === '') {\r
@@ -106,7 +107,10 @@ rng.modules.visualEditor = function(sandbox) {
                 todel.remove();\r
             }\r
             var newNode = this._createNode(wlxmlTag || anchor.attr('wlxml-tag'), wlxmlClass || anchor.attr('wlxml-class'));\r
                 todel.remove();\r
             }\r
             var newNode = this._createNode(wlxmlTag || anchor.attr('wlxml-tag'), wlxmlClass || anchor.attr('wlxml-class'));\r
-            anchor.after(newNode);\r
+            if(anchorOffset === 0)\r
+                anchor.before(newNode)\r
+            else\r
+                anchor.after(newNode);\r
             mediator.nodeCreated(newNode);\r
             isDirty = true;\r
         },\r
             mediator.nodeCreated(newNode);\r
             isDirty = true;\r
         },\r