[gnome-builder/gnome-builder-3-30] completion: improve fuzzy matching



commit a0a80662f73a6d6ba6b1a477ce97fd4ac2d80ad2
Author: Christian Hergert <chergert redhat com>
Date:   Thu Oct 25 11:57:56 2018 -0700

    completion: improve fuzzy matching
    
    This ensures that we match 'E' before 'e' in 'Endianness' if the input
    character is 'e'. Otherwise, 'end' won't match and that is not the
    expected behavior.
    
    This just takes the earliest of 'E' or 'e' as the match for any character
    that has a toupper() variant, at the cost of running additional matches.
    
    This code does need to stay fast, but it seemed fast enough in testing.
    
    Fixes #673

 src/libide/completion/ide-completion.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/src/libide/completion/ide-completion.c b/src/libide/completion/ide-completion.c
index 70f7278c5..42172880b 100644
--- a/src/libide/completion/ide-completion.c
+++ b/src/libide/completion/ide-completion.c
@@ -1664,7 +1664,10 @@ ide_completion_fuzzy_match (const gchar *haystack,
   for (; *casefold_needle; casefold_needle = g_utf8_next_char (casefold_needle))
     {
       gunichar ch = g_utf8_get_char (casefold_needle);
+      gunichar chup = g_unichar_toupper (ch);
       const gchar *tmp;
+      const gchar *downtmp;
+      const gchar *uptmp;
 
       /*
        * Note that the following code is not really correct. We want
@@ -1675,14 +1678,17 @@ ide_completion_fuzzy_match (const gchar *haystack,
        * for function names and symbols.
        */
 
-      tmp = strchr (haystack, ch);
+      downtmp = strchr (haystack, ch);
+      uptmp = strchr (haystack, chup);
 
-      if (tmp == NULL)
-        {
-          tmp = strchr (haystack, g_unichar_toupper (ch));
-          if (tmp == NULL)
-            return FALSE;
-        }
+      if (downtmp && uptmp)
+        tmp = MIN (downtmp, uptmp);
+      else if (downtmp)
+        tmp = downtmp;
+      else if (uptmp)
+        tmp = uptmp;
+      else
+        return FALSE;
 
       /*
        * Here we calculate the cost of this character into the score.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]