Revision: 28868
          http://sourceforge.net/p/bibdesk/svn/28868
Author:   hofman
Date:     2024-04-26 16:01:59 +0000 (Fri, 26 Apr 2024)
Log Message:
-----------
find fully matched completion in matching loop

Modified Paths:
--------------
    trunk/bibdesk/BDSKCompletionManager.m

Modified: trunk/bibdesk/BDSKCompletionManager.m
===================================================================
--- trunk/bibdesk/BDSKCompletionManager.m       2024-04-26 15:53:50 UTC (rev 
28867)
+++ trunk/bibdesk/BDSKCompletionManager.m       2024-04-26 16:01:59 UTC (rev 
28868)
@@ -285,29 +285,25 @@
 - (NSArray *)possibleMatches:(NSMapTable *)definitions 
forBibTeXString:(NSString *)fullString partialWordRange:(NSRange)charRange 
indexOfBestMatch:(NSInteger *)idx{
     NSString *partialString = [fullString substringWithRange:charRange];
     NSMutableArray *matches = [NSMutableArray array];
-    NSString *key = nil;
+    NSString *bestMatch = nil;
     
     // Search the definitions case-insensitively; we match on key or value, 
but only return keys.
-    for (key in definitions) {
+    for (NSString *key in definitions) {
         if ([key rangeOfString:partialString 
options:NSCaseInsensitiveSearch].location != NSNotFound ||
-            ([definitions objectForKey:key] != nil && [[definitions 
objectForKey:key] rangeOfString:partialString 
options:NSCaseInsensitiveSearch].location != NSNotFound))
+            ([definitions objectForKey:key] != nil && [[definitions 
objectForKey:key] rangeOfString:partialString 
options:NSCaseInsensitiveSearch].location != NSNotFound)) {
             [matches addObject:key];
+            if ([key isCaseInsensitiveEqual:partialString] || (bestMatch == 
nil && [key hasPrefix:partialString]))
+                bestMatch = key;
+        }
     }
     [matches sortUsingSelector:@selector(caseInsensitiveCompare:)];
     
-    NSInteger i, count = [matches count];
-    for (i = 0; i < count; i++) {
-        key = [matches objectAtIndex:i];
-        if ([key hasPrefix:partialString]) {
-            // If the key has the entire partialString as prefix, it's a good 
match, so we'll select it by default.
-            *idx = i;
-                       break;
-        }
-    }
+    if (bestMatch)
+        *idx = [matches indexOfObject:bestMatch];
     
     // we show the expansion in the list, this is removed by possibleMatch: 
when actually inserting
     NSMutableArray *displayMatches = [NSMutableArray array];
-    for (key in matches)
+    for (NSString *key in matches)
         [displayMatches addObject:[NSString stringWithFormat:@"%@ [%@]", key, 
[definitions objectForKey:key]]];
     
     return displayMatches;

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

Reply via email to