Revision: 29059
http://sourceforge.net/p/bibdesk/svn/29059
Author: hofman
Date: 2025-02-24 15:17:46 +0000 (Mon, 24 Feb 2025)
Log Message:
-----------
get missing range boundary group from correct array of groups
Modified Paths:
--------------
trunk/bibdesk/BibDocument+Scripting.m
Modified: trunk/bibdesk/BibDocument+Scripting.m
===================================================================
--- trunk/bibdesk/BibDocument+Scripting.m 2025-02-24 09:49:30 UTC (rev
29058)
+++ trunk/bibdesk/BibDocument+Scripting.m 2025-02-24 15:17:46 UTC (rev
29059)
@@ -731,74 +731,82 @@
if ([allGroups count] == 0)
// If there are no groups, there can be no match. Just return now.
return @[];
-
+
if ((startSpec == nil || [groupKeys() containsObject:startKey]) &&
(endSpec == nil || [groupKeys() containsObject:endKey])) {
- NSInteger startIndex;
- NSInteger endIndex;
-
+ BOOL keyIsGroups = [key isEqual:@"scriptingGroups"];
+ NSArray *rangeKeyObjects = (keyIsGroups ? nil : [self
valueForKey:key]);
+ NSUInteger startIndex;
+ NSUInteger endIndex;
+ id object;
+
+ if (keyIsGroups == NO && [rangeKeyObjects count] == 0)
+ // If there are no groups for the key, there can be no match.
Just return now.
+ return @[];
+
// The start and end keys are also ones we want to handle.
// The strategy here is going to be to find the index of the start
and stop object in the full groups array, regardless of what its key is. Then
we can find what we're looking for in that range of the groups key (weeding out
objects we don't want, if necessary).
-
+
// First find the index of the first start object in the groups
array
- if (startSpec) {
- id startObject = [startSpec
objectsByEvaluatingWithContainers:self];
- if ([startObject isKindOfClass:[NSArray class]])
- startObject = [startObject firstObject];
- if (startObject == nil)
- // Oops. We could not find the start object.
- return nil;
+ if (startSpec == nil && keyIsGroups) {
+ startIndex = 0;
+ } else {
+ if (startSpec) {
+ object = [startSpec
objectsByEvaluatingWithContainers:self];
+ if ([object isKindOfClass:[NSArray class]])
+ object = [object firstObject];
+ if (object == nil)
+ // Oops. We could not find the start object.
+ return nil;
+ } else {
+ object = [rangeKeyObjects firstObject];
+ }
- startIndex = [allGroups indexOfObjectIdenticalTo:startObject];
+ startIndex = [allGroups indexOfObjectIdenticalTo:object];
if (startIndex == NSNotFound)
// Oops. We couldn't find the start object in the groups
array. This should not happen.
return nil;
-
- } else {
- startIndex = 0;
}
-
+
// Now find the index of the last end object in the groups array
- if (endSpec) {
- id endObject = [endSpec
objectsByEvaluatingWithContainers:self];
- if ([endObject isKindOfClass:[NSArray class]])
- endObject = [endObject lastObject];
- if (endObject == nil)
- // Oops. We could not find the end object.
- return nil;
+ if (endSpec == nil && keyIsGroups) {
+ endIndex = [allGroups count] - 1;
+ } else {
+ if (endSpec) {
+ object = [endSpec objectsByEvaluatingWithContainers:self];
+ if ([object isKindOfClass:[NSArray class]])
+ object = [object lastObject];
+ if (object == nil)
+ // Oops. We could not find the end object.
+ return nil;
+ } else {
+ object = [rangeKeyObjects lastObject];
+ }
- endIndex = [allGroups indexOfObjectIdenticalTo:endObject];
+ endIndex = [allGroups indexOfObjectIdenticalTo:object];
if (endIndex == NSNotFound)
// Oops. We couldn't find the end object in the groups
array. This should not happen.
return nil;
-
- } else {
- endIndex = [allGroups count] - 1;
}
-
+
if (endIndex < startIndex) {
// Accept backwards ranges gracefully
- NSInteger temp = endIndex;
+ NSUInteger temp = endIndex;
endIndex = startIndex;
startIndex = temp;
}
-
+
// Now startIndex and endIndex specify the end points of the range
we want within the groups array.
// We will traverse the range and pick the objects we want.
// We do this by getting each object and seeing if it actually
appears in the real key that we are trying to evaluate in.
NSMutableArray *result = [NSMutableArray array];
- BOOL keyIsGroups = [key isEqual:@"scriptingGroups"];
- NSArray *rangeKeyObjects = (keyIsGroups ? nil : [self
valueForKey:key]);
- id curObj;
- NSUInteger curKeyIndex;
- NSInteger i;
-
- for (i = startIndex; i <= endIndex; i++) {
+
+ for (NSUInteger i = startIndex; i <= endIndex; i++) {
if (keyIsGroups) {
[result addObject:[NSNumber numberWithInteger:i]];
} else {
- curObj = [allGroups objectAtIndex:i];
- curKeyIndex = [rangeKeyObjects
indexOfObjectIdenticalTo:curObj];
+ object = [allGroups objectAtIndex:i];
+ NSUInteger curKeyIndex = [rangeKeyObjects
indexOfObjectIdenticalTo:object];
if (curKeyIndex != NSNotFound)
[result addObject:[NSNumber
numberWithInteger:curKeyIndex]];
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit