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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
From a05a54825446a6caa0e17600538bc7583564bcd7 Mon Sep 17 00:00:00 2001
From: Xavier Claessens <xavier.claessens@collabora.com>
Date: Tue, 7 Apr 2026 22:16:56 +0200
Subject: [PATCH 2/2] Restore typeahead support for keyboard navigation
Co-Authored-By: Bryan Lai <bryanlais@gmail.com>
Co-Authored-By: DragoonAethis <dragoon@dragonic.eu>
Co-Authored-By: Kevin MacMartin <prurigro@gmail.com>
Co-Authored-By: Daniel Rudolf <gnome.org@daniel-rudolf.de>
---
data/org.gnome.nautilus.gschema.xml | 5 +
src/nautilus-files-view.c | 14 ++
src/nautilus-files-view.h | 5 +
src/nautilus-global-preferences.h | 1 +
src/nautilus-preferences-dialog.c | 5 +
src/nautilus-query-editor.c | 6 +
src/nautilus-window-slot.c | 139 ++++++++++++++----
.../ui/nautilus-preferences-dialog.blp | 12 ++
8 files changed, 158 insertions(+), 29 deletions(-)
diff --git a/data/org.gnome.nautilus.gschema.xml b/data/org.gnome.nautilus.gschema.xml
index 3c14aa4d5..0af9e1d3a 100644
--- a/data/org.gnome.nautilus.gschema.xml
+++ b/data/org.gnome.nautilus.gschema.xml
@@ -82,6 +82,11 @@
<summary>Always use the location entry, instead of the pathbar</summary>
<description>If set to true, Files will always use a textual input entry for the location toolbar, instead of the pathbar.</description>
</key>
+ <key type="b" name="type-ahead-search">
+ <default>true</default>
+ <summary>Start searching on type ahead</summary>
+ <description>If set to true, typing on the files viewer will start searching. Otherwise it select first matching file.</description>
+ </key>
<key name="recursive-search" enum="org.gnome.nautilus.SpeedTradeoff">
<default>'local-only'</default>
<summary>Where to perform recursive search</summary>
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 236d00a1f..f81790920 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -9787,3 +9787,17 @@ nautilus_files_view_get_private_list_base (NautilusFilesView *self)
{
return self->list_base;
}
+
+void
+nautilus_files_view_get_sort_state(NautilusFilesView *view,
+ GQuark *sort_attribute,
+ gboolean *reversed,
+ gboolean *directories_first)
+{
+ g_autoptr(GVariant) value = nautilus_list_base_get_sort_state(view->list_base);
+ const gchar *target_name;
+ g_variant_get(value, "(&sb)", &target_name, reversed);
+ *sort_attribute = g_quark_from_string(target_name);
+ *directories_first = g_settings_get_boolean(gtk_filechooser_preferences,
+ NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST);
+}
diff --git a/src/nautilus-files-view.h b/src/nautilus-files-view.h
index a020ed808..b9b19102c 100644
--- a/src/nautilus-files-view.h
+++ b/src/nautilus-files-view.h
@@ -131,4 +131,9 @@ nautilus_files_view_get_private_action_group (NautilusFilesView *self);
NautilusListBase *
nautilus_files_view_get_private_list_base (NautilusFilesView *self);
+void nautilus_files_view_get_sort_state (NautilusFilesView *view,
+ GQuark *sort_attribute,
+ gboolean *reversed,
+ gboolean *directories_first);
+
G_END_DECLS
diff --git a/src/nautilus-global-preferences.h b/src/nautilus-global-preferences.h
index ca08bfaa6..05a5c7f36 100644
--- a/src/nautilus-global-preferences.h
+++ b/src/nautilus-global-preferences.h
@@ -114,6 +114,7 @@ typedef enum
/* Search behaviour */
#define NAUTILUS_PREFERENCES_RECURSIVE_SEARCH "recursive-search"
+#define NAUTILUS_PREFERENCES_TYPE_AHEAD_SEARCH "type-ahead-search"
/* Context menu options */
#define NAUTILUS_PREFERENCES_SHOW_DELETE_PERMANENTLY "show-delete-permanently"
diff --git a/src/nautilus-preferences-dialog.c b/src/nautilus-preferences-dialog.c
index de009fa39..1e9e98a28 100644
--- a/src/nautilus-preferences-dialog.c
+++ b/src/nautilus-preferences-dialog.c
@@ -42,6 +42,8 @@
"show_create_link_row"
#define NAUTILUS_PREFERENCES_DIALOG_LIST_VIEW_USE_TREE_WIDGET \
"use_tree_view_row"
+#define NAUTILUS_PREFERENCES_DIALOG_TYPE_AHEAD_WIDGET \
+ "type_ahead_search"
/* combo preferences */
#define NAUTILUS_PREFERENCES_DIALOG_OPEN_ACTION_COMBO \
@@ -184,6 +186,9 @@ nautilus_preferences_dialog_setup (GtkBuilder *builder)
bind_builder_bool (builder, nautilus_preferences,
NAUTILUS_PREFERENCES_DIALOG_DELETE_PERMANENTLY_WIDGET,
NAUTILUS_PREFERENCES_SHOW_DELETE_PERMANENTLY);
+ bind_builder_bool (builder, nautilus_preferences,
+ NAUTILUS_PREFERENCES_DIALOG_TYPE_AHEAD_WIDGET,
+ NAUTILUS_PREFERENCES_TYPE_AHEAD_SEARCH);
setup_detailed_date (builder);
diff --git a/src/nautilus-query-editor.c b/src/nautilus-query-editor.c
index 30514fb45..9e80287c0 100644
--- a/src/nautilus-query-editor.c
+++ b/src/nautilus-query-editor.c
@@ -816,6 +816,12 @@ nautilus_query_editor_set_query (NautilusQueryEditor *self,
g_return_if_fail (NAUTILUS_IS_QUERY_EDITOR (self));
+ /* Setting query to NULL causes reentry to set it to an empty query */
+ if (self->change_frozen) {
+ g_set_object (&self->query, query);
+ return;
+ }
+
if (query != NULL)
{
text = nautilus_query_get_text (query);
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index 2e2c7bcfb..4fa7619b5 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -81,6 +81,9 @@ enum
static guint signals[LAST_SIGNAL];
+/* In type ahead mode, clear entry if it did not change for a while */
+#define CLEAR_QUERY_EDITOR_TIMEOUT 1000
+
struct _NautilusWindowSlot
{
AdwBin parent_instance;
@@ -125,6 +128,7 @@ struct _NautilusWindowSlot
/* Query editor */
NautilusQueryEditor *query_editor;
NautilusQuery *pending_search_query;
+ guint clear_query_editor_timeout_id;
/* Banner */
AdwBanner *banner;
@@ -380,20 +384,107 @@ query_editor_focus_view_callback (NautilusQueryEditor *editor,
}
}
+static GFile *
+nautilus_window_slot_get_current_location(NautilusWindowSlot *self)
+{
+ if (self->pending_location != NULL)
+ {
+ return self->pending_location;
+ }
+
+ return self->location;
+}
+
+static gboolean
+type_ahead_search (void)
+{
+ return g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_TYPE_AHEAD_SEARCH);
+}
+
+static gboolean
+clear_query_editor_timeout_callback (NautilusWindowSlot *self)
+{
+ nautilus_query_editor_set_query (self->query_editor, NULL);
+ self->clear_query_editor_timeout_id = 0;
+ return G_SOURCE_REMOVE;
+}
+
+typedef struct {
+ GQuark sort_attribute;
+ gboolean directories_first;
+ gboolean reversed;
+} FileCompareForTypeAheadContext;
+
+static int
+file_compare_for_type_ahead (gconstpointer a, gconstpointer b, gpointer user_data)
+{
+ FileCompareForTypeAheadContext *ctx = user_data;
+ return nautilus_file_compare_for_sort_by_attribute_q(NAUTILUS_FILE (a),
+ NAUTILUS_FILE (b),
+ ctx->sort_attribute,
+ ctx->directories_first,
+ ctx->reversed);
+}
+
static void
query_editor_changed_callback (NautilusQueryEditor *editor,
NautilusQuery *query,
gboolean reload,
NautilusWindowSlot *self)
{
- nautilus_files_view_set_search_query (self->content_view, query);
+ if (nautilus_window_slot_get_search_visible (self))
+ {
+ nautilus_files_view_set_search_query(self->content_view, query);
- /* Setting search query may cause the view to load a new location. */
- GFile *location = nautilus_files_view_get_location (self->content_view);
- guint view_id = nautilus_window_slot_get_view_id_for_location (self, location);
+ /* Setting search query may cause the view to load a new location. */
+ GFile *location = nautilus_files_view_get_location (self->content_view);
+ guint view_id = nautilus_window_slot_get_view_id_for_location (self, location);
- nautilus_window_slot_set_location (self, location);
- nautilus_window_slot_set_view_id (self, view_id);
+ nautilus_window_slot_set_location (self, location);
+ nautilus_window_slot_set_view_id (self, view_id);
+ }
+ else
+ {
+ /* Find all files with a display name that starts with the query, case insensitive. */
+ GFile *location = nautilus_window_slot_get_current_location (self);
+ g_autoptr (NautilusDirectory) directory = nautilus_directory_get (location);
+ const gchar *text = nautilus_query_get_text (query);
+ g_autofree gchar *text_casefold = g_utf8_casefold (text, -1);
+ g_autofree gchar *text_collate = g_utf8_collate_key_for_filename (text_casefold, -1);
+ gsize text_len = strlen (text);
+ g_autolist (NautilusFile) files = nautilus_directory_get_file_list (directory);
+ g_autolist (NautilusFile) matches = NULL;
+ GList *l;
+
+ for (l = files; l; l = l->next)
+ {
+ NautilusFile *file = NAUTILUS_FILE (l->data);
+ const gchar *name = nautilus_file_get_display_name(file);
+ g_autofree gchar *name_casefold = g_utf8_casefold(name, text_len);
+ g_autofree gchar *name_collate = g_utf8_collate_key_for_filename(name_casefold, -1);
+
+ if (g_str_equal (name_collate, text_collate))
+ {
+ matches = g_list_prepend (matches, nautilus_file_ref (file));
+ }
+ }
+
+ /* Select the first match */
+ if (matches != NULL)
+ {
+ FileCompareForTypeAheadContext ctx;
+ nautilus_files_view_get_sort_state (NAUTILUS_FILES_VIEW (self->content_view), &ctx.sort_attribute, &ctx.reversed, &ctx.directories_first);
+ matches = g_list_sort_with_data (matches, file_compare_for_type_ahead, &ctx);
+ g_autolist(NautilusFile) selection = g_list_prepend (NULL, g_object_ref (matches->data));
+ nautilus_files_view_set_selection (self->content_view, selection, TRUE);
+ }
+
+ /* Reset timeout that clears type ahead query */
+ g_clear_handle_id (&self->clear_query_editor_timeout_id, g_source_remove);
+ self->clear_query_editor_timeout_id = g_timeout_add (CLEAR_QUERY_EDITOR_TIMEOUT,
+ G_SOURCE_FUNC (clear_query_editor_timeout_callback),
+ self);
+ }
}
static void
@@ -401,8 +492,6 @@ hide_query_editor (NautilusWindowSlot *self)
{
NautilusFilesView *view = self->content_view;
- g_signal_handlers_disconnect_by_data (self->query_editor, self);
-
nautilus_query_editor_set_query (self->query_editor, NULL);
if (nautilus_files_view_is_searching (view))
@@ -436,17 +525,6 @@ hide_query_editor (NautilusWindowSlot *self)
}
}
-static GFile *
-nautilus_window_slot_get_current_location (NautilusWindowSlot *self)
-{
- if (self->pending_location != NULL)
- {
- return self->pending_location;
- }
-
- return self->location;
-}
-
static void
show_query_editor (NautilusWindowSlot *self)
{
@@ -466,15 +544,6 @@ show_query_editor (NautilusWindowSlot *self)
}
gtk_widget_grab_focus (GTK_WIDGET (self->query_editor));
-
- g_signal_connect (self->query_editor, "changed",
- G_CALLBACK (query_editor_changed_callback), self);
- g_signal_connect (self->query_editor, "cancel",
- G_CALLBACK (query_editor_cancel_callback), self);
- g_signal_connect (self->query_editor, "activated",
- G_CALLBACK (query_editor_activated_callback), self);
- g_signal_connect (self->query_editor, "focus-view",
- G_CALLBACK (query_editor_focus_view_callback), self);
}
static void
@@ -606,7 +675,7 @@ nautilus_window_slot_handle_event (NautilusWindowSlot *self,
state);
}
- if (retval)
+ if (retval && type_ahead_search ())
{
nautilus_window_slot_set_search_visible (self, TRUE);
}
@@ -885,6 +954,15 @@ nautilus_window_slot_constructed (GObject *object)
gtk_box_append (GTK_BOX (self->vbox), extras_vbox);
self->query_editor = NAUTILUS_QUERY_EDITOR (nautilus_query_editor_new ());
+ g_signal_connect (self->query_editor, "changed",
+ G_CALLBACK (query_editor_changed_callback), self);
+ g_signal_connect (self->query_editor, "cancel",
+ G_CALLBACK (query_editor_cancel_callback), self);
+ g_signal_connect (self->query_editor, "activated",
+ G_CALLBACK (query_editor_activated_callback), self);
+ g_signal_connect (self->query_editor, "focus-view",
+ G_CALLBACK (query_editor_focus_view_callback), self);
+
/* We want to keep alive the query editor betwen additions and removals on the
* UI, specifically when the toolbar adds or removes it */
g_object_ref_sink (self->query_editor);
@@ -2144,6 +2222,9 @@ apply_pending_location_and_selection_on_view (NautilusWindowSlot *self)
nautilus_file_list_free (self->pending_selection);
self->pending_selection = NULL;
+ nautilus_query_editor_set_query (self->query_editor, NULL);
+ g_clear_handle_id (&self->clear_query_editor_timeout_id, g_source_remove);
+
if (self->pending_file_to_activate != NULL)
{
g_autoptr (GAppInfo) app_info = NULL;
diff --git a/src/resources/ui/nautilus-preferences-dialog.blp b/src/resources/ui/nautilus-preferences-dialog.blp
index 259ac1a2e..f6bb17c68 100644
--- a/src/resources/ui/nautilus-preferences-dialog.blp
+++ b/src/resources/ui/nautilus-preferences-dialog.blp
@@ -24,6 +24,18 @@ Adw.PreferencesDialog preferences_dialog {
title: _("_Action to Open Items");
use-underline: true;
}
+
+ Adw.ActionRow type_ahead_search_row {
+ title: _("_Search on type ahead");
+ use-underline: true;
+
+ [prefix]
+ Switch type_ahead_search {
+ valign: center;
+ }
+
+ activatable-widget: type_ahead_search;
+ }
}
Adw.PreferencesGroup {
--
2.53.0
|