gedit/gedit-document-selector-make-search-caseless.patch

78 lines
2.0 KiB
Diff

From a622fda63726adaabd02fa0c1786b75a921b1973 Mon Sep 17 00:00:00 2001
From: Sebastien Lafargue <slafargue@gnome.org>
Date: Mon, 19 Nov 2018 19:46:56 +0100
Subject: [PATCH] document selector: make search caseless
---
gedit/gedit-open-document-selector.c | 36 +++++++++++++++++++++++-----
1 file changed, 30 insertions(+), 6 deletions(-)
diff --git a/gedit/gedit-open-document-selector.c b/gedit/gedit-open-document-selector.c
index 5389ef0bd..3e3d9a293 100644
--- a/gedit/gedit-open-document-selector.c
+++ b/gedit/gedit-open-document-selector.c
@@ -436,6 +436,23 @@ fileitem_setup (FileItem *item)
return candidate;
}
+static inline gboolean
+is_filter_in_candidate (const gchar *candidate,
+ const gchar *filter)
+{
+ gchar *candidate_fold;
+ gboolean ret;
+
+ g_assert (candidate != NULL);
+ g_assert (filter != NULL);
+
+ candidate_fold = g_utf8_casefold (candidate, -1);
+ ret = (strstr (candidate_fold, filter) != NULL);
+
+ g_free (candidate_fold);
+ return ret;
+}
+
/* If filter == NULL then items are
* not checked against the filter.
*/
@@ -445,6 +462,10 @@ fileitem_list_filter (GList *items,
{
GList *new_items = NULL;
GList *l;
+ gchar *filter_fold = NULL;
+
+ if (filter != NULL)
+ filter_fold = g_utf8_casefold (filter, -1);
for (l = items; l != NULL; l = l->next)
{
@@ -453,16 +474,19 @@ fileitem_list_filter (GList *items,
item = l->data;
candidate = fileitem_setup (item);
-
- if (candidate && (filter == NULL || strstr (candidate, filter)))
+ if (candidate != NULL)
{
- new_items = g_list_prepend (new_items,
- gedit_open_document_selector_copy_fileitem_item (item));
- }
+ if (filter == NULL || is_filter_in_candidate (candidate, filter_fold))
+ {
+ new_items = g_list_prepend (new_items,
+ gedit_open_document_selector_copy_fileitem_item (item));
+ }
- g_free (candidate);
+ g_free (candidate);
+ }
}
+ g_free (filter_fold);
new_items = g_list_reverse (new_items);
return new_items;
}
--
2.18.1