From 2390a92e90ce831cf87c87c2c48b80f85c47fa99 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 19 Apr 2013 16:01:22 +0200 Subject: [PATCH] Visual editor: selecting created node FF doesn't put carret at the end of new node, Chrome does. --- modules/visualEditor.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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); } -- 2.20.1