Skip to content

Commit 851b0de

Browse files
committed
codenav/goto_file: Tab keys shows the autocomplete list if not visible
1 parent e510d89 commit 851b0de

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

codenav/src/goto_file.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,17 @@ entry_key_event(GtkEntry *entry, GdkEventKey *key, GtkEntryCompletion *completio
266266

267267
if(key->keyval == GDK_KEY_Tab)
268268
{
269-
/* The user may 'accept' the autocomplete's suggestion with the Tab key,
269+
/* The user can use the Tab key to 'accept' the autocomplete's suggestion,
270270
* like in shells, and in GtkFileChoose. If there's a suggestion, it will
271271
* be selected, and we may simply move the cursor to accept it. */
272272
if(gtk_editable_get_selection_bounds(GTK_EDITABLE(entry), NULL, &end_pos))
273-
{
274273
gtk_editable_set_position(GTK_EDITABLE(entry), end_pos);
275274

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

281281
/* The 2nd purpose of the Tab key is to trigger the procedure that
282282
* calculates and suggests an inline completion. FYI doing this here
@@ -359,17 +359,16 @@ create_dialog(GtkWidget **dialog)
359359
gtk_entry_completion_set_text_column (completion, 0);
360360
gtk_entry_completion_set_minimum_key_length(completion, 0);
361361

362+
/* Initialize a model for the completion, to avoid errors in code that
363+
* might attempt to utilize it, before any 'changed' events are fired. */
364+
directory_check(GTK_ENTRY(entry), completion);
365+
362366
/* Signals */
363367
g_signal_connect_after(entry, "changed",
364368
G_CALLBACK(directory_check), completion);
365369
g_signal_connect(completion, "insert-prefix",
366370
G_CALLBACK(entry_inline_completion_event), entry);
367371

368-
/* Manual trigger to invoke directory_check to put together
369-
* a completion model (for the reference dirrectory), and to
370-
* show the completion options as soon as the dialog opens. */
371-
g_signal_emit_by_name(entry, "changed");
372-
373372
gtk_widget_show_all(*dialog);
374373

375374
return entry;

0 commit comments

Comments
 (0)