From 258a2d6877a76d51253f5f70d4a7df6bfe81b90f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Sun, 5 May 2013 21:46:55 +0200 Subject: [PATCH] Visual editor - inserting node before the current one if anchorOffset is 0 --- modules/visualEditor.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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; }, -- 2.20.1