From: Aleksander Ɓukasz Date: Tue, 22 Apr 2014 12:16:30 +0000 (+0200) Subject: editor: WrapTextAction plays nice and returns a new document fragment X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/81a52f1229a0514560d601208f75f3e73e1e614d editor: WrapTextAction plays nice and returns a new document fragment --- diff --git a/src/editor/plugins/core/core.js b/src/editor/plugins/core/core.js index 5d3a57f..a780227 100644 --- a/src/editor/plugins/core/core.js +++ b/src/editor/plugins/core/core.js @@ -172,13 +172,21 @@ var createWrapTextAction = function(createParams) { description: createParams.description, execute: function(callback, params) { params.fragment.document.transaction(function() { - var parent = params.fragment.startNode.parent(); - return parent.wrapText({ + var parent = params.fragment.startNode.parent(), + doc = params.fragment.document, + wrapper, lastTextNode; + + wrapper = parent.wrapText({ _with: {tagName: 'span', attrs: {'class': createParams.klass}}, offsetStart: params.fragment.startOffset, offsetEnd: params.fragment.endOffset, textNodeIdx: [params.fragment.startNode.getIndex(), params.fragment.endNode.getIndex()] }); + + lastTextNode = wrapper.getLastTextNode(); + if(lastTextNode) { + return doc.createFragment(doc.CaretFragment, {node: lastTextNode, offset: lastTextNode.getText().length}); + } }, { metadata: { description: createParams.description