diff --git a/src/item/Layer.js b/src/item/Layer.js index d357c7d9..09a940bd 100644 --- a/src/item/Layer.js +++ b/src/item/Layer.js @@ -98,7 +98,7 @@ var Layer = this.Layer = Group.extend(/** @lends Layer# */{ if (item instanceof Layer && !item._parent && this._remove(false, true)) { Base.splice(item._project.layers, [this], - item._index + (above ? 1 : -1), 0); + item._index + (above ? 1 : 0), 0); this._setProject(item._project); return true; } diff --git a/test/tests/Layer.js b/test/tests/Layer.js index 98945878..139d1ad6 100644 --- a/test/tests/Layer.js +++ b/test/tests/Layer.js @@ -59,9 +59,19 @@ test('insertAbove / insertBelow', function() { var project = paper.project; var firstLayer = project.activeLayer; var secondLayer = new Layer(); + var thirdLayer = new Layer(); + + thirdLayer.insertBelow(firstLayer); + equals(function() { + return thirdLayer.previousSibling == null; + }, true); + equals(function() { + return thirdLayer.nextSibling == firstLayer; + }, true); + secondLayer.insertBelow(firstLayer); equals(function() { - return secondLayer.previousSibling == null; + return secondLayer.previousSibling == thirdLayer; }, true); equals(function() { return secondLayer.nextSibling == firstLayer; @@ -78,10 +88,10 @@ test('insertAbove / insertBelow', function() { equals(function() { return secondLayer.parent == firstLayer; }, true); - // There should now only be one layer left: + // There should now only be two layers left: equals(function() { return project.layers.length; - }, 1); + }, 2); }); test('addChild / appendBottom / nesting', function() { @@ -114,4 +124,4 @@ test('addChild / appendBottom / nesting', function() { return project.layers[0] == secondLayer && project.layers[1] == firstLayer; }, true); -}); \ No newline at end of file +});