mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Handle reinsertion of items into the same children list.
Fixes failing test.
This commit is contained in:
parent
881f624575
commit
0599aabdb9
2 changed files with 13 additions and 3 deletions
|
@ -392,6 +392,8 @@ this.Base = Base.inject(/** @lends Base# */{
|
|||
var amount = items && items.length,
|
||||
append = index === undefined;
|
||||
index = append ? list.length : index;
|
||||
if (index > list.length)
|
||||
index = list.length;
|
||||
// Update _index on the items to be added first.
|
||||
for (var i = 0; i < amount; i++)
|
||||
items[i]._index = index + i;
|
||||
|
|
|
@ -1271,10 +1271,18 @@ var Item = this.Item = Base.extend(Callback, {
|
|||
// an Item#children array. Use Array.prototype.slice because
|
||||
// in certain cases items is an arguments object
|
||||
items = items && Array.prototype.slice.apply(items);
|
||||
var i = index;
|
||||
var children = this._children,
|
||||
length = children.length,
|
||||
i = index;
|
||||
for (var j = 0, l = items && items.length; j < l; j++) {
|
||||
if (this.insertChild(i, items[j], _cloning))
|
||||
i++;
|
||||
if (this.insertChild(i, items[j], _cloning)) {
|
||||
// We need to keep track of how much the list actually grows,
|
||||
// bcause we might be removing and inserting into the same list,
|
||||
// in which case the size would not chage.
|
||||
var newLength = children.length;
|
||||
i += newLength - length;
|
||||
length = newLength;
|
||||
}
|
||||
}
|
||||
return i != index;
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue