Fixed: if CPArrayController setPreserveSelection was off and a selected item disappeared, an invalid selection state could occur. The error was caused by a slightly overeager early-out optimisation in __setSelectionIndexes.

This commit is contained in:
Alexander Ljungberg
2010-09-04 22:12:08 -04:00
parent c489909542
commit e704d42adb
2 changed files with 22 additions and 3 deletions
+19
View File
@@ -113,6 +113,25 @@
[self assert:[CPIndexSet indexSet] equals:[arrayController selectionIndexes] message:@"no objects left, selection should disappear"];
}
- (void)testSelectionWhenObjectsDisappear
{
// If the selected object disappeares during a rearrange, the selection
// should update appropriately, even if preserve selection is off.
var arrayController = [self arrayController];
[arrayController setPreservesSelection:NO];
// Use a copy to make sure our original remains pristine.
[arrayController setSelectionIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, 3)]];
var newContent = [[self contentArray] copy];
[newContent removeObjectAtIndex:2];
[arrayController setContent:newContent];
[self assert:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, 2)] equals:[arrayController selectionIndexes]
message:@"last object cannot be selected"];
}
- (void)testContentBinding
{
[[self arrayController] bind:@"contentArray" toObject:self withKeyPath:@"contentArray" options:0];