From 08c02a66f19b8cd9435e003dbda19fadf1c9fdce Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Tue, 13 Mar 2012 15:58:52 +0100 Subject: [PATCH] Fix Item#insertAbove(item) & Item#insertBelow(item). Closes #81 --- src/item/Item.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index eee96c77..1496b70b 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -1169,8 +1169,10 @@ function(name) { * @return {Boolean} {@true it was inserted} */ insertAbove: function(item) { - return item._parent && item._parent.insertChild( - item._index + 1, this); + var index = item._index; + if (item._parent == this._parent && index < this._index) + index++; + return item._parent.insertChild(index, this); }, /** @@ -1180,8 +1182,10 @@ function(name) { * @return {Boolean} {@true it was inserted} */ insertBelow: function(item) { - return item._parent && item._parent.insertChild( - item._index - 1, this); + var index = item._index; + if (item._parent == this._parent && index > this._index) + index--; + return item._parent.insertChild(index, this); }, /**