editor: WrapTextAction plays nice and returns a new document fragment
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 22 Apr 2014 12:16:30 +0000 (14:16 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 23 Apr 2014 11:05:06 +0000 (13:05 +0200)
src/editor/plugins/core/core.js

index 5d3a57f..a780227 100644 (file)
@@ -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