Skip to content

Commit 6d6b2e8

Browse files
committed
codenav/goto_file: Tab keys shows the autocomplete list if not visible
1 parent cb97d8c commit 6d6b2e8

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
@@ -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
@@ -361,17 +361,16 @@ create_dialog(GtkWidget **dialog)
361361
gtk_entry_completion_set_text_column (completion, 0);
362362
gtk_entry_completion_set_minimum_key_length(completion, 0);
363363

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

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

377376
return entry;

0 commit comments

Comments
 (0)