From: Aleksander Ɓukasz Date: Fri, 19 Apr 2013 14:01:22 +0000 (+0200) Subject: Visual editor: selecting created node X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/2390a92e90ce831cf87c87c2c48b80f85c47fa99?ds=inline Visual editor: selecting created node FF doesn't put carret at the end of new node, Chrome does. --- diff --git a/modules/visualEditor.js b/modules/visualEditor.js index 9cec971..bb4ad31 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -143,7 +143,11 @@ rng.modules.visualEditor = function(sandbox) { var prefix = node.data.substr(0, startOffset); var suffix = node.data.substr(endOffset); var core = node.data.substr(startOffset, endOffset - startOffset); - $(node).replaceWith(prefix + '' + core + '' + suffix); + var newNode = $('' + core + ''); + $(node).replaceWith(newNode); + newNode.before(prefix); + newNode.after(suffix); + mediator.nodeCreated(newNode); isDirty = true; } }); @@ -168,6 +172,18 @@ rng.modules.visualEditor = function(sandbox) { getCurrentNode: function() { return view.currentNode; }, + nodeCreated: function(node) { + view._markSelected(node); + + var range = document.createRange(); + range.selectNodeContents(node[0]); + range.collapse(false); + + var selection = document.getSelection(); + selection.removeAllRanges() + selection.addRange(range); + + }, nodeSelected: function(node) { sideBarView.updateEditPane(node); }