Handle reinsertion of items into the same children list.

Fixes failing test.
This commit is contained in:
Jürg Lehni 2013-03-01 23:06:29 -08:00
parent 881f624575
commit 0599aabdb9
2 changed files with 13 additions and 3 deletions

View file

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

View file

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