From c17a3533ecae63d479b285b23ac3a490ebe8bd3c Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Tue, 20 Jul 2010 14:59:18 +0200 Subject: [PATCH] fix #764 Array controller inserts object in wrong arranged object position if there are no sort descriptors defined --- AppKit/CPArrayController.j | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/AppKit/CPArrayController.j b/AppKit/CPArrayController.j index c11206f79..72aab18f4 100644 --- a/AppKit/CPArrayController.j +++ b/AppKit/CPArrayController.j @@ -400,16 +400,23 @@ if (_filterPredicate === nil || [_filterPredicate evaluateWithObject:object]) { - var pos = [_arrangedObjects insertObject:object inArraySortedByDescriptors:_sortDescriptors]; + var position; + if ([_sortDescriptors count] > 0) + position = [_arrangedObjects insertObject:object inArraySortedByDescriptors:_sortDescriptors]; + else + { + [_arrangedObjects addObject:object]; + position = [_arrangedObjects count] - 1; + } if (_selectsInsertedObjects) { - [self setSelectionIndex:pos]; + [self setSelectionIndex:position]; } else { [self willChangeValueForKey:@"selectionIndexes"]; - [_selectionIndexes shiftIndexesStartingAtIndex:pos by:1]; + [_selectionIndexes shiftIndexesStartingAtIndex:position by:1]; [self didChangeValueForKey:@"selectionIndexes"]; } }