From bf5ebc6402774afb306abcc8af78749ce5178e7e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 8 Aug 2014 10:54:56 +0200 Subject: [PATCH] editor: prevent list action from operating across context root boundries --- .../modules/documentCanvas/canvas/selection.js | 16 ++++++++++++---- src/editor/plugins/core/lists.js | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/editor/modules/documentCanvas/canvas/selection.js b/src/editor/modules/documentCanvas/canvas/selection.js index e072050..0d8c4ce 100644 --- a/src/editor/modules/documentCanvas/canvas/selection.js +++ b/src/editor/modules/documentCanvas/canvas/selection.js @@ -60,7 +60,8 @@ $.extend(TextSelection.prototype, { toDocumentFragment: function() { var doc = this.canvas.wlxmlDocument, anchorNode = this.anchorElement ? this.anchorElement.wlxmlNode : null, - focusNode = this.focusElement ? this.focusElement.wlxmlNode : null; + focusNode = this.focusElement ? this.focusElement.wlxmlNode : null, + node1, node2; if(!anchorNode || !focusNode) { return; @@ -75,10 +76,17 @@ $.extend(TextSelection.prototype, { }); } else { - var siblingParents = doc.getSiblingParents({node1: anchorNode, node2: focusNode}); + if(anchorNode.hasSameContextRoot(focusNode)) { + var siblingParents = doc.getSiblingParents({node1: anchorNode, node2: focusNode}); + node1 = siblingParents.node1; + node2 = siblingParents.node2; + } else { + node1 = focusNode; + node2 = anchorNode; + } return doc.createFragment(doc.RangeFragment, { - node1: siblingParents.node1, - node2: siblingParents.node2 + node1: node1, + node2: node2 }); } }, diff --git a/src/editor/plugins/core/lists.js b/src/editor/plugins/core/lists.js index c6de730..65b6e69 100644 --- a/src/editor/plugins/core/lists.js +++ b/src/editor/plugins/core/lists.js @@ -8,7 +8,7 @@ var getBoundriesForAList = function(fragment) { var node; if(fragment instanceof fragment.RangeFragment && fragment.hasSiblingBoundries()) { - return fragment.boundriesSiblingParents(); + return fragment.startNode.hasSameContextRoot(fragment.endNode) && fragment.boundriesSiblingParents(); } if(fragment instanceof fragment.NodeFragment) { node = fragment.node.getNearestElementNode(); @@ -156,7 +156,7 @@ var toggleListAction = function(type) { } var boundries = getBoundriesForAList(params.fragment); - if(boundries) { + if(boundries && boundries.node1.hasSameContextRoot(boundries.node2)) { return { allowed: true, description: interpolate(gettext('Make %s fragment(s) into list'), [countItems(getBoundriesForAList(params.fragment))]), -- 2.20.1