Merge pull request #135 from 0/layer-insert-below

Fix insertBelow for Layer items
This commit is contained in:
Jonathan Puckey 2012-11-23 12:05:11 -08:00
commit 4c409b37fb
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 if (item instanceof Layer && !item._parent
&& this._remove(false, true)) { && this._remove(false, true)) {
Base.splice(item._project.layers, [this], Base.splice(item._project.layers, [this],
item._index + (above ? 1 : -1), 0); item._index + (above ? 1 : 0), 0);
this._setProject(item._project); this._setProject(item._project);
return true; return true;
} }

View file

@ -59,9 +59,19 @@ test('insertAbove / insertBelow', function() {
var project = paper.project; var project = paper.project;
var firstLayer = project.activeLayer; var firstLayer = project.activeLayer;
var secondLayer = new Layer(); 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); secondLayer.insertBelow(firstLayer);
equals(function() { equals(function() {
return secondLayer.previousSibling == null; return secondLayer.previousSibling == thirdLayer;
}, true); }, true);
equals(function() { equals(function() {
return secondLayer.nextSibling == firstLayer; return secondLayer.nextSibling == firstLayer;
@ -78,10 +88,10 @@ test('insertAbove / insertBelow', function() {
equals(function() { equals(function() {
return secondLayer.parent == firstLayer; return secondLayer.parent == firstLayer;
}, true); }, true);
// There should now only be one layer left: // There should now only be two layers left:
equals(function() { equals(function() {
return project.layers.length; return project.layers.length;
}, 1); }, 2);
}); });
test('addChild / appendBottom / nesting', function() { test('addChild / appendBottom / nesting', function() {