Skip to content

Commit 8469496

Browse files
author
You name
committed
feat: match anywhere in filename during interactive search
Previously, type-ahead search only matched at the start of filenames. Now it matches anywhere in the filename (case insensitive). For example, typing 'demo' will now find 'preview-demo.gif'. Applies to both icon view and list view. Closes linuxmint#2660
1 parent 3200500 commit 8469496

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

libnemo-private/nemo-icon-container.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3875,8 +3875,7 @@ nemo_icon_container_search_iter (NemoIconContainer *container,
38753875
continue;
38763876
}
38773877

3878-
if (strncmp (case_normalized_key, case_normalized_name,
3879-
strlen (case_normalized_key)) == 0) {
3878+
if (strstr (case_normalized_name, case_normalized_key) != NULL) {
38803879
count++;
38813880
}
38823881

src/nemo-list-view.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,53 @@ G_DEFINE_TYPE (NemoListView, nemo_list_view, NEMO_TYPE_VIEW);
191191

192192
static gint click_policy = NEMO_CLICK_POLICY_SINGLE;
193193

194+
static gboolean
195+
list_view_search_equal_func (GtkTreeModel *model,
196+
gint search_column,
197+
const gchar *key,
198+
GtkTreeIter *iter,
199+
gpointer user_data)
200+
{
201+
gchar *name = NULL;
202+
gchar *normalized_key = NULL;
203+
gchar *case_normalized_key = NULL;
204+
gchar *normalized_name = NULL;
205+
gchar *case_normalized_name = NULL;
206+
gboolean is_match = FALSE;
207+
208+
(void) user_data;
209+
210+
if (key == NULL || key[0] == '\0') {
211+
return TRUE;
212+
}
213+
214+
gtk_tree_model_get (model, iter, search_column, &name, -1);
215+
if (name == NULL) {
216+
return TRUE;
217+
}
218+
219+
normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
220+
normalized_name = g_utf8_normalize (name, -1, G_NORMALIZE_ALL);
221+
222+
if (normalized_key != NULL && normalized_name != NULL) {
223+
case_normalized_key = g_utf8_casefold (normalized_key, -1);
224+
case_normalized_name = g_utf8_casefold (normalized_name, -1);
225+
226+
if (case_normalized_key != NULL && case_normalized_name != NULL) {
227+
is_match = strstr (case_normalized_name, case_normalized_key) != NULL;
228+
}
229+
}
230+
231+
g_free (case_normalized_name);
232+
g_free (normalized_name);
233+
g_free (case_normalized_key);
234+
g_free (normalized_key);
235+
g_free (name);
236+
237+
/* GtkTreeView expects FALSE for a row that matches. */
238+
return !is_match;
239+
}
240+
194241
static const char * default_trash_visible_columns[] = {
195242
"name", "size", "type", "trashed_on", "trash_orig_path", NULL
196243
};
@@ -2538,6 +2585,10 @@ create_and_set_up_tree_view (NemoListView *view)
25382585
NULL);
25392586

25402587
gtk_tree_view_set_enable_search (view->details->tree_view, TRUE);
2588+
gtk_tree_view_set_search_equal_func (view->details->tree_view,
2589+
list_view_search_equal_func,
2590+
view,
2591+
NULL);
25412592

25422593
/* Don't handle backspace key. It's used to open the parent folder. */
25432594
binding_set = gtk_binding_set_by_class (GTK_WIDGET_GET_CLASS (view->details->tree_view));

0 commit comments

Comments
 (0)