From: Aleksander Ɓukasz Date: Thu, 26 Jun 2014 09:40:44 +0000 (+0200) Subject: editor: fix splitting text when its parent contains comments X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/aba92db36cedd657b0c8c0637aa4aae7b573f023?ds=sidebyside editor: fix splitting text when its parent contains comments --- diff --git a/src/editor/plugins/core/core.js b/src/editor/plugins/core/core.js index c12405b..450f147 100644 --- a/src/editor/plugins/core/core.js +++ b/src/editor/plugins/core/core.js @@ -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() {