Revision: 28873
          http://sourceforge.net/p/bibdesk/svn/28873
Author:   hofman
Date:     2024-04-28 14:32:56 +0000 (Sun, 28 Apr 2024)
Log Message:
-----------
Display prefix matches for macros before substring matches and matches to 
expansion in completion list, makes it also easy to find a full string match as 
it will be the first one if any.

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

Modified: trunk/bibdesk/BDSKCompletionManager.m
===================================================================
--- trunk/bibdesk/BDSKCompletionManager.m       2024-04-27 15:49:12 UTC (rev 
28872)
+++ trunk/bibdesk/BDSKCompletionManager.m       2024-04-28 14:32:56 UTC (rev 
28873)
@@ -262,7 +262,7 @@
     
     [completions 
sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
     
-    if (matched)
+    if (matched && idx)
         *idx = [completions indexOfObject:matched];
     
     return completions;
@@ -289,22 +289,28 @@
 - (NSArray *)possibleMatches:(NSMapTable *)definitions 
forBibTeXString:(NSString *)fullString partialWordRange:(NSRange)charRange 
indexOfBestMatch:(NSInteger *)idx{
     NSString *partialString = [fullString substringWithRange:charRange];
     NSMutableArray *matches = [NSMutableArray array];
-    NSString *bestMatch = nil;
+    NSMutableArray *subMatches = [NSMutableArray array];
     
     // Search the definitions case-insensitively; we match on key or value, 
but only return keys.
     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)) {
-            [matches addObject:key];
-            if ([key isCaseInsensitiveEqual:partialString] || (bestMatch == 
nil && [key hasPrefix:partialString]))
-                bestMatch = key;
+        NSRange range = [key rangeOfString:partialString 
options:NSCaseInsensitiveSearch];
+        if (range.location != NSNotFound) {
+            if (range.location == 0)
+                [matches addObject:key];
+            else
+                [subMatches addObject:key];
+        } else if ([[definitions objectForKey:key] 
hasCaseInsensitivePrefix:partialString]) {
+            [subMatches addObject:key];
         }
     }
     [matches sortUsingSelector:@selector(caseInsensitiveCompare:)];
+    [subMatches sortUsingSelector:@selector(caseInsensitiveCompare:)];
     
-    if (bestMatch)
-        *idx = [matches indexOfObject:bestMatch];
+    if ([[matches firstObject] length] == [partialString length])
+        *idx = 0;
     
+    [matches addObjectsFromArray:subMatches];
+    
     // we show the expansion in the list, this is removed by possibleMatch: 
when actually inserting
     NSMutableArray *displayMatches = [NSMutableArray array];
     for (NSString *key in matches)

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
Bibdesk-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to