Package: gedit / 3.30.2-2

document-selector-make-search-caseless.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
From: Sebastien Lafargue <slafargue@gnome.org>
Date: Mon, 19 Nov 2018 19:46:56 +0100
Subject: document selector: make search caseless

(cherry picked from commit a622fda63726adaabd02fa0c1786b75a921b1973)
---
 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 5389ef0..3e3d9a2 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;
 }