mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Fix to remove named layer
This commit is contained in:
parent
75a10fb246
commit
31690cb6b6
3 changed files with 18 additions and 4 deletions
|
@ -125,7 +125,7 @@ var Emitter = {
|
|||
if (func)
|
||||
func.call(this, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -2549,6 +2549,9 @@ new function() { // Injection scope for hit-test functions shared with project
|
|||
project = this._project,
|
||||
index = this._index;
|
||||
if (owner) {
|
||||
// Handle named children separately from index:
|
||||
if (this._name)
|
||||
this._removeNamed();
|
||||
// Handle index separately from owner: There are situations where
|
||||
// the item is already removed from its list through Base.splice()
|
||||
// and index set to undefined, but the owner is still set,
|
||||
|
@ -2560,9 +2563,6 @@ new function() { // Injection scope for hit-test functions shared with project
|
|||
|| this.getPreviousSibling();
|
||||
Base.splice(owner._children, null, index, 1);
|
||||
}
|
||||
// Handle named children separately from index:
|
||||
if (this._name)
|
||||
this._removeNamed();
|
||||
this._installEvents(false);
|
||||
// Notify self of the insertion change. We only need this
|
||||
// notification if we're tracking changes for now.
|
||||
|
|
|
@ -125,3 +125,17 @@ test('addChild / appendBottom / nesting', function() {
|
|||
&& project.layers[1] == firstLayer;
|
||||
}, true);
|
||||
});
|
||||
|
||||
test('remove', function(){
|
||||
var layer1 = new Layer({name: 'test-layer'});
|
||||
var layer2 = new Layer({name: 'test-layer'});
|
||||
var removeCount = 0;
|
||||
while (project.layers['test-layer']) {
|
||||
project.layers['test-layer'].remove();
|
||||
++removeCount;
|
||||
if (removeCount > 2) break;
|
||||
}
|
||||
equals(function(){
|
||||
return removeCount;
|
||||
}, 2);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue