Fix insertBelow for Layer objects

This commit is contained in:
Dmitri Iouchtchenko 2012-11-19 23:41:04 -05:00
parent bb5bc4e85a
commit ae7e6ee6b3
2 changed files with 15 additions and 5 deletions

View file

@ -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;
}

View file

@ -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);
});
});