X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/9201c5810622e27a19de7e331046108d7110c46b..3733d5e0527a89111f9e33bb8380fed20ea768fc:/modules/visualEditor.js diff --git a/modules/visualEditor.js b/modules/visualEditor.js index 70fc435..bb4ad31 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -131,7 +131,7 @@ rng.modules.visualEditor = function(sandbox) { view.node.on('change', '.rng-visualEditor-editPaneSelectionForm select', function(e) { var target = $(e.target); var selection = window.getSelection(); - if(selection.anchorNode.isSameNode(selection.focusNode) && selection.anchorNode.nodeType === Node.TEXT_NODE) { + if(selection.anchorNode === selection.focusNode && selection.anchorNode.nodeType === Node.TEXT_NODE) { var startOffset = selection.anchorOffset; var endOffset = selection.focusOffset; if(startOffset > endOffset) { @@ -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); }