mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Fix a bug in Item#_removeNamed() for items without parents.
Closes #490.
This commit is contained in:
parent
04a0c995bc
commit
56704b9206
1 changed files with 22 additions and 19 deletions
|
@ -2183,25 +2183,28 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
* Removes the item from its parent's named children list.
|
* Removes the item from its parent's named children list.
|
||||||
*/
|
*/
|
||||||
_removeNamed: function() {
|
_removeNamed: function() {
|
||||||
var children = this._parent._children,
|
var parent = this._parent;
|
||||||
namedChildren = this._parent._namedChildren,
|
if (parent) {
|
||||||
name = this._name,
|
var children = parent._children,
|
||||||
namedArray = namedChildren[name],
|
namedChildren = parent._namedChildren,
|
||||||
index = namedArray ? namedArray.indexOf(this) : -1;
|
name = this._name,
|
||||||
if (index == -1)
|
namedArray = namedChildren[name],
|
||||||
return;
|
index = namedArray ? namedArray.indexOf(this) : -1;
|
||||||
// Remove the named reference
|
if (index !== -1) {
|
||||||
if (children[name] == this)
|
// Remove the named reference
|
||||||
delete children[name];
|
if (children[name] == this)
|
||||||
// Remove this entry
|
delete children[name];
|
||||||
namedArray.splice(index, 1);
|
// Remove this entry
|
||||||
// If there are any items left in the named array, set
|
namedArray.splice(index, 1);
|
||||||
// the last of them to be this.parent.children[this.name]
|
// If there are any items left in the named array, set
|
||||||
if (namedArray.length) {
|
// the last of them to be this.parent.children[this.name]
|
||||||
children[name] = namedArray[namedArray.length - 1];
|
if (namedArray.length) {
|
||||||
} else {
|
children[name] = namedArray[namedArray.length - 1];
|
||||||
// Otherwise delete the empty array
|
} else {
|
||||||
delete namedChildren[name];
|
// Otherwise delete the empty array
|
||||||
|
delete namedChildren[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue