From 31771aa01d634fd4aba5131d2c56700482b7b2cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 30 Aug 2015 14:47:46 +0200 Subject: [PATCH] Insert results of boolean operations above whichever of the two paths appear further up in the stack. --- src/item/Item.js | 10 ++++++++++ src/path/PathItem.Boolean.js | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/item/Item.js b/src/item/Item.js index 8e3718d5..122f4f2f 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -2664,6 +2664,16 @@ var Item = Base.extend(Emitter, /** @lends Item# */{ return item ? item.isDescendant(this) : false; }, + /** + * Checks if the item is an a sibling of the specified item. + * + * @param {Item} item the item to check against + * @return {Boolean} {@true if the item is aa sibling of the specified item} + */ + isSibling: function(item) { + return this._parent === item._parent; + }, + /** * Checks whether the item is grouped with the specified item. * diff --git a/src/path/PathItem.Boolean.js b/src/path/PathItem.Boolean.js index efa78650..ad92aed1 100644 --- a/src/path/PathItem.Boolean.js +++ b/src/path/PathItem.Boolean.js @@ -216,7 +216,11 @@ PathItem.inject(new function() { true); // See if the CompoundPath can be reduced to just a simple Path. result = result.reduce(); - result.insertAbove(path1); + // Insert the resulting path above whichever of the two paths appear + // further up in the stack. + result.insertAbove(path2 && path1.isSibling(path2) + && path1.getIndex() < path2.getIndex() + ? path2 : path1); // Copy over the left-hand item's style and we're done. // TODO: Consider using Item#_clone() for this, but find a way to not // clone children / name (content).