Skip to content

Commit 732e06f

Browse files
committed
codenav/goto_file: Tab keys shows the autocomplete list if not visible
1 parent 653c9ad commit 732e06f

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

codenav/src/goto_file.c

+13-11
Original file line numberDiff line numberDiff line change
@@ -268,17 +268,17 @@ entry_key_event(GtkEntry *entry, GdkEventKey *key, GtkEntryCompletion *completio
268268

269269
if(key->keyval == GDK_KEY_Tab)
270270
{
271-
/* The user may 'accept' the autocomplete's suggestion with the Tab key,
271+
/* The user can use the Tab key to 'accept' the autocomplete's suggestion,
272272
* like in shells, and in GtkFileChoose. If there's a suggestion, it will
273273
* be selected, and we may simply move the cursor to accept it. */
274274
if(gtk_editable_get_selection_bounds(GTK_EDITABLE(entry), NULL, &end_pos))
275-
{
276275
gtk_editable_set_position(GTK_EDITABLE(entry), end_pos);
277276

278-
/* Moving the cursor does not trigger the "changed" event. Do it
279-
* manually, to caclulate & show completions for the new path. */
280-
g_signal_emit_by_name(entry, "changed");
281-
}
277+
/* The Tab key may also be used to trigger the autocomplete list
278+
* to show up. And this trigger right here after 'accepting' an
279+
* autocomplete suggestion is also useful in order to calculate
280+
* and show completions for the new path. */
281+
g_signal_emit_by_name(entry, "changed");
282282

283283
/* The 2nd purpose of the Tab key is to trigger the procedure that
284284
* calculates and suggests an inline completion. FYI doing this here
@@ -360,6 +360,13 @@ create_dialog(GtkWidget **dialog)
360360
gtk_entry_completion_set_text_column (completion, 0);
361361
gtk_entry_completion_set_minimum_key_length(completion, 0);
362362

363+
/* Initialize a model for the completion, to avoid errors in code that
364+
* might attempt to utilize it, before any 'changed' events are fired. */
365+
directory_check(GTK_ENTRY(entry), completion);
366+
367+
/* Manual trigger to show the completion list as soon as the dialog opens */
368+
g_signal_emit_by_name(entry, "changed");
369+
363370
/* Signals */
364371
g_signal_connect_after(entry, "changed",
365372
G_CALLBACK(directory_check), completion);
@@ -370,11 +377,6 @@ create_dialog(GtkWidget **dialog)
370377
* reference, and it will be deallocated when the entry is destroyed. */
371378
g_object_unref(completion);
372379

373-
/* Manual trigger to invoke directory_check to put together
374-
* a completion model (for the reference dirrectory), and to
375-
* show the completion options as soon as the dialog opens. */
376-
g_signal_emit_by_name(entry, "changed");
377-
378380
gtk_widget_show_all(*dialog);
379381

380382
return entry;

0 commit comments

Comments
 (0)