[gnome-control-center] keyboard: Follow the usual search pattern for filtering



commit 3910b4ac9d97db87b7fdfd959dbc51af899f8164
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Jun 29 19:09:03 2017 +0200

    keyboard: Follow the usual search pattern for filtering
    
    Filtering on the name currently only matches the string as a whole,
    not individual words as expected, for instance "home fo" and "ho fo"
    should both match "Home Folder".
    
    https://bugzilla.gnome.org/show_bug.cgi?id=784357

 panels/keyboard/cc-keyboard-panel.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/panels/keyboard/cc-keyboard-panel.c b/panels/keyboard/cc-keyboard-panel.c
index ad0f0e7..82afdfb 100644
--- a/panels/keyboard/cc-keyboard-panel.c
+++ b/panels/keyboard/cc-keyboard-panel.c
@@ -547,6 +547,8 @@ filter_function (GtkListBoxRow *row,
   RowData *data;
   gboolean retval;
   gchar *search, *name;
+  gchar **terms;
+  guint i;
 
   if (gtk_entry_get_text_length (GTK_ENTRY (self->search_entry)) == 0)
     return TRUE;
@@ -559,11 +561,18 @@ filter_function (GtkListBoxRow *row,
   item = data->item;
   name = cc_util_normalize_casefold_and_unaccent (item->description);
   search = cc_util_normalize_casefold_and_unaccent (gtk_entry_get_text (GTK_ENTRY (self->search_entry)));
+  terms = g_strsplit (search, " ", -1);
 
-  retval = strstr (name, search) != NULL || search_match_shortcut (item, search);
+  for (i = 0; terms && terms[i]; i++)
+    {
+      retval = strstr (name, terms[i]) || search_match_shortcut (item, terms[i]);
+      if (!retval)
+        break;
+    }
 
   g_free (search);
   g_free (name);
+  g_strfreev (terms);
 
   return retval;
 }


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