[gnome-text-editor] sidebaritem: remove use of GPatternSpec



commit fde3266f5ca38e6420fbaa4b1c8e81982ec762ac
Author: Christian Hergert <chergert redhat com>
Date:   Thu Oct 28 19:58:33 2021 -0700

    sidebaritem: remove use of GPatternSpec
    
    We can do fuzzy matching here instead which is closer to how auto
    completion would work in the editor anyway (not that we do that currently).
    
    It also removes the use of GPatternSpec which is a bit tricky to use in a
    fast fashion anyway and overkill for our needs here.
    
    Related #192

 src/editor-open-popover.c         | 12 ++++--------
 src/editor-sidebar-item-private.h |  2 +-
 src/editor-sidebar-item.c         | 10 +++++-----
 3 files changed, 10 insertions(+), 14 deletions(-)
---
diff --git a/src/editor-open-popover.c b/src/editor-open-popover.c
index d79253e..abbc97c 100644
--- a/src/editor-open-popover.c
+++ b/src/editor-open-popover.c
@@ -122,12 +122,9 @@ editor_sidebar_filter_func_cb (gpointer itemptr,
                                gpointer user_data)
 {
   EditorSidebarItem *item = itemptr;
-  GPatternSpec *spec = user_data;
+  const char *search = user_data;
 
-  g_assert (EDITOR_IS_SIDEBAR_ITEM (item));
-  g_assert (spec != NULL);
-
-  return _editor_sidebar_item_matches (item, spec);
+  return _editor_sidebar_item_matches (item, search);
 }
 
 static void
@@ -151,12 +148,11 @@ on_search_entry_changed_cb (EditorOpenPopover *self,
   else
     {
       g_autofree gchar *text_fold = g_utf8_casefold (text, -1);
-      g_autofree gchar *pattern = g_strdup_printf ("*%s*", g_strdelimit (text_fold, " \n\t", '*'));
       g_autoptr(GtkCustomFilter) custom = NULL;
 
       custom = gtk_custom_filter_new (editor_sidebar_filter_func_cb,
-                                      g_pattern_spec_new (pattern),
-                                      (GDestroyNotify) g_pattern_spec_free);
+                                      g_steal_pointer (&text_fold),
+                                      g_free);
       filter = gtk_filter_list_model_new (g_object_ref (G_LIST_MODEL (self->model)),
                                           g_object_ref (GTK_FILTER (custom)));
       model = G_LIST_MODEL (filter);
diff --git a/src/editor-sidebar-item-private.h b/src/editor-sidebar-item-private.h
index 1dd09d0..d757a73 100644
--- a/src/editor-sidebar-item-private.h
+++ b/src/editor-sidebar-item-private.h
@@ -53,7 +53,7 @@ void               _editor_sidebar_item_open            (EditorSidebarItem *self
                                                          EditorSession     *session,
                                                          EditorWindow      *window);
 gboolean           _editor_sidebar_item_matches         (EditorSidebarItem *self,
-                                                         GPatternSpec      *spec);
+                                                         const char        *search);
 int                _editor_sidebar_item_compare         (EditorSidebarItem *a,
                                                          EditorSidebarItem *b);
 
diff --git a/src/editor-sidebar-item.c b/src/editor-sidebar-item.c
index 1726d4a..823c6fd 100644
--- a/src/editor-sidebar-item.c
+++ b/src/editor-sidebar-item.c
@@ -511,14 +511,14 @@ _editor_sidebar_item_get_empty (EditorSidebarItem *self)
 
 gboolean
 _editor_sidebar_item_matches (EditorSidebarItem *self,
-                              GPatternSpec      *spec)
+                              const char        *search)
 {
-  g_return_val_if_fail (EDITOR_IS_SIDEBAR_ITEM (self), FALSE);
+  guint prio;
 
-  if (spec == NULL)
+  if (search == NULL)
     return TRUE;
 
-  if (self->search_text == NULL)
+  if G_UNLIKELY (self->search_text == NULL)
     {
       g_autofree gchar *title = _editor_sidebar_item_dup_title (self);
       g_autofree gchar *subtitle = _editor_sidebar_item_dup_subtitle (self);
@@ -528,7 +528,7 @@ _editor_sidebar_item_matches (EditorSidebarItem *self,
       self->search_text = g_strdup_printf ("%s %s", title_fold, subtitle_fold);
     }
 
-  return g_pattern_spec_match_string (spec, self->search_text);
+  return gtk_source_completion_fuzzy_match (self->search_text, search, &prio);
 }
 
 void


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