fixed: selection issues

This commit is contained in:
daboe01
2026-03-08 19:52:58 +01:00
parent c70079ae71
commit 031e5e7ca3
4 changed files with 34 additions and 30 deletions
+15 -14
View File
@@ -1110,7 +1110,7 @@ var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
var parent = itemInfo.parent;
// Check if the parent is the root item because we never return the actual root item
if (parent && itemInfo[[parent UID]] === _rootItemInfo)
if (parent && _itemInfosForItems[[parent UID]] === _rootItemInfo)
parent = nil;
return parent;
@@ -2531,25 +2531,26 @@ var colorForDisclosureTriangle = function(isSelected, isHighlighted)
BOOL _isSyncingFromModel;
}
- (void)bind
- (id)initWithBinding:(CPString)aBinding name:(CPString)aName to:(id)aDestination keyPath:(CPString)aKeyPath options:(CPDictionary)options from:(id)aSource
{
[super bind];
[[CPNotificationCenter defaultCenter]
self = [super initWithBinding:aBinding name:aName to:aDestination keyPath:aKeyPath options:options from:aSource];
[[CPNotificationCenter defaultCenter]
addObserver:self
selector:@selector(outlineViewSelectionDidChange:)
name:CPOutlineViewSelectionDidChangeNotification
object:_source];
object:aSource];
}
- (void)unbind
+ (void)unbind:(CPString)aBinding forObject:(id)anObject
{
[[CPNotificationCenter defaultCenter]
removeObserver:self
name:CPOutlineViewSelectionDidChangeNotification
object:_source];
[super unbind];
if (aBinding === "selectionIndexPaths")
[[CPNotificationCenter defaultCenter]
removeObserver:self
name:CPOutlineViewSelectionDidChangeNotification
object:anObject];
[super unbind:aBinding forObject:anObject];
}
- (void)setValueFor:(CPString)aBinding
@@ -2606,7 +2607,7 @@ var colorForDisclosureTriangle = function(isSelected, isHighlighted)
if (_isSyncingFromModel)
return;
// In CPBinder, reverseSetValueFor: takes the name of the property on _source
// In CPBinder, reverseSetValueFor: takes the name of the property on _source
// it should fetch the updated value from. Since CPOutlineView has the selectionIndexPaths method:
[self reverseSetValueFor:@"selectionIndexPaths"];
}
-1
View File
@@ -300,7 +300,6 @@
[self willChangeValueForKey:@"selectionIndexPaths"];
_selectionIndexPaths = [newPaths copy];
var binderClass = [[self class] _binderClassForBinding:@"selectionIndexPaths"];
+18 -14
View File
@@ -54,7 +54,8 @@
// If we have a parent, calculate path based on parent's path + our index
if (_parentNode)
{
var index = [_childNodes indexOfObjectIdenticalTo:self];
// Search the parent's child nodes, not our own!
var index = [[_parentNode childNodes] indexOfObjectIdenticalTo:self];
// If the parent is the root (and technically has no path itself in some implementations),
// we might get nil. Handle that gracefully.
@@ -68,7 +69,7 @@
// If we are the root, we don't have an index path in the context of a tree controller usually,
// or we are [] (empty path). Returning nil is acceptable for the absolute root.
return nil;
return nil;
}
- (BOOL)isLeaf
@@ -167,18 +168,21 @@
if (!indexPath || [indexPath length] == 0)
return self;
var index = [indexPath indexAtPosition:0],
count = [_childNodes count];
if (index >= count)
return nil;
var child = [_childNodes objectAtIndex:index];
if ([indexPath length] == 1)
return child;
return [child descendantNodeAtIndexPath:[indexPath indexPathByRemovingFirstIndex]];
var node = self,
length = [indexPath length];
for (var i = 0; i < length; i++)
{
var index = [indexPath indexAtPosition:i],
count = [node count];
if (index >= count || index < 0)
return nil;
node = [node objectAtIndex:index];
}
return node;
}
@end
+1 -1
View File
@@ -25,7 +25,7 @@
indexPath = [CPIndexPath indexPathWithIndex:1];
[self assert:undefined equals:[treeNode descendantNodeAtIndexPath:indexPath]];
[self assert:nil equals:[treeNode descendantNodeAtIndexPath:indexPath]];
}
@end