X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/1ffafa96f9858a9eb43d3a66d7593ae0cbf090d1..9201c5810622e27a19de7e331046108d7110c46b:/modules/visualEditor.js diff --git a/modules/visualEditor.js b/modules/visualEditor.js index 8a96cb9..70fc435 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -127,6 +127,26 @@ 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.isSameNode(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); + $(node).replaceWith(prefix + '' + core + '' + suffix); + isDirty = true; + } + }); }, selectTab: function(id) { this.node.find('.rng-visualEditor-sidebarContentItem').hide();