editor: fix splitting text when its parent contains comments
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 26 Jun 2014 09:40:44 +0000 (11:40 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 26 Jun 2014 09:40:44 +0000 (11:40 +0200)
src/editor/plugins/core/core.js

index c12405b..450f147 100644 (file)
@@ -18,22 +18,27 @@ plugin.documentExtension.textNode.transformations = {
     breakContent: {
         impl: function(args) {
             var node = this,
+                parentDescribingNodes = [],
                 newNodes, emptyText;
             newNodes = node.split({offset: args.offset});
-            [newNodes.first, newNodes.second].some(function(newNode) {
-                if(!(newNode.contents().length)) {
-                    emptyText = newNode.append({text: ''});
-                    return true; // break
-                }
-            });
             newNodes.second.contents()
                 .filter(function(child) {
                     return child.object.describesParent;
                 })
                 .forEach(function(child) {
                     //child.detach();
-                    newNodes.first.append(child);
+                    parentDescribingNodes.push(child);
+                    child.detach();
                 });
+            [newNodes.first, newNodes.second].some(function(newNode) {
+                if(!(newNode.contents().length)) {
+                    emptyText = newNode.append({text: ''});
+                    return true; // break
+                }
+            });
+            parentDescribingNodes.forEach(function(node) {
+                newNodes.first.append(node);
+            });
             return _.extend(newNodes, {emptyText: emptyText});
         },
         getChangeRoot: function() {