From: Aleksander Ɓukasz Date: Sun, 5 May 2013 19:46:55 +0000 (+0200) Subject: Visual editor - inserting node before the current one if anchorOffset is 0 X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/258a2d6877a76d51253f5f70d4a7df6bfe81b90f?hp=f1a5428285aa5741b76bf9a7c64bcdeecf6d1916 Visual editor - inserting node before the current one if anchorOffset is 0 --- diff --git a/modules/visualEditor.js b/modules/visualEditor.js index 17e7f73..012f7a9 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -98,6 +98,7 @@ rng.modules.visualEditor = function(sandbox) { insertNewNode: function(wlxmlTag, wlxmlClass) { //TODO: Insert inline var anchor = $(window.getSelection().anchorNode); + var anchorOffset = window.getSelection().anchorOffset; if(anchor[0].nodeType === Node.TEXT_NODE) anchor = anchor.parent(); if(anchor.text() === '') { @@ -106,7 +107,10 @@ rng.modules.visualEditor = function(sandbox) { todel.remove(); } var newNode = this._createNode(wlxmlTag || anchor.attr('wlxml-tag'), wlxmlClass || anchor.attr('wlxml-class')); - anchor.after(newNode); + if(anchorOffset === 0) + anchor.before(newNode) + else + anchor.after(newNode); mediator.nodeCreated(newNode); isDirty = true; },