From 81a52f1229a0514560d601208f75f3e73e1e614d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Tue, 22 Apr 2014 14:16:30 +0200 Subject: [PATCH] editor: WrapTextAction plays nice and returns a new document fragment --- src/editor/plugins/core/core.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 -- 2.20.1