[gedit/gnome-3-30] document selector: make search caseless
- From: Sébastien Lafargue <slafargue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/gnome-3-30] document selector: make search caseless
- Date: Tue, 20 Nov 2018 17:23:03 +0000 (UTC)
commit a622fda63726adaabd02fa0c1786b75a921b1973
Author: Sebastien Lafargue <slafargue gnome org>
Date: Mon Nov 19 19:46:56 2018 +0100
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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]