X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/6c3dfb35e4a92d05de9ffcfd7d6e23a9a9cb32fe..3733d5e0527a89111f9e33bb8380fed20ea768fc:/modules/visualEditor.js diff --git a/modules/visualEditor.js b/modules/visualEditor.js index 8a96cb9..bb4ad31 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -127,6 +127,30 @@ rng.modules.visualEditor = function(sandbox) { mediator.getCurrentNode().attr('wlxml-'+attr, target.val()); isDirty = true; }); + + view.node.on('change', '.rng-visualEditor-editPaneSelectionForm select', function(e) { + var target = $(e.target); + var selection = window.getSelection(); + if(selection.anchorNode === selection.focusNode && selection.anchorNode.nodeType === Node.TEXT_NODE) { + var startOffset = selection.anchorOffset; + var endOffset = selection.focusOffset; + if(startOffset > endOffset) { + var tmp = startOffset; + startOffset = endOffset; + endOffset = tmp; + } + var node = selection.anchorNode; + var prefix = node.data.substr(0, startOffset); + var suffix = node.data.substr(endOffset); + var core = node.data.substr(startOffset, endOffset - startOffset); + var newNode = $('' + core + ''); + $(node).replaceWith(newNode); + newNode.before(prefix); + newNode.after(suffix); + mediator.nodeCreated(newNode); + isDirty = true; + } + }); }, selectTab: function(id) { this.node.find('.rng-visualEditor-sidebarContentItem').hide(); @@ -148,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); }