diff --git a/AppKit/CPArrayController.j b/AppKit/CPArrayController.j index 42ad4acc3..2f72ad429 100644 --- a/AppKit/CPArrayController.j +++ b/AppKit/CPArrayController.j @@ -771,7 +771,8 @@ } /*! - Adds an object at a given index to the receiver's collection. + Adds an object at a given index in the receiver's arrangedObjects. Also add the object + to the content collection (although at the end rather than the given index). @param id anObject - The object to add to the collection. @param int anIndex - The index to insert the object at. @@ -790,7 +791,10 @@ See _disableSetContent explanation in addObject:. */ _disableSetContent = YES; - [_contentObject insertObject:anObject atIndex:anIndex]; + // The atArrangedObjectIndex: part of this method's name only refers to where the + // object goes in arrangedObjects, not in the content array. So use addObject:, + // not insertObject:atIndex: here for speed. + [_contentObject addObject:anObject]; _disableSetContent = NO; if (_clearsFilterPredicateOnInsertion) diff --git a/Tests/AppKit/CPArrayControllerTest.j b/Tests/AppKit/CPArrayControllerTest.j index 992852b9f..aa76c3f5c 100644 --- a/Tests/AppKit/CPArrayControllerTest.j +++ b/Tests/AppKit/CPArrayControllerTest.j @@ -80,6 +80,7 @@ [arrayController insertObject:object atArrangedObjectIndex:1]; [self assert:object equals:[[arrayController arrangedObjects] objectAtIndex:1]]; + [self assertTrue:[[arrayController content] containsObject:object] message:@"object should be inserted into content"]; } - (void)testAddObjectUpdatesArrangedObjectsWithoutSortDescriptors