From ea35b8e9d23356bef0b75b67f1f45f08bae60717 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Sun, 22 Nov 2015 22:30:05 +0100 Subject: [PATCH] Use sorting for completion by default. This makes the codes easeir to read, because the most completions should be sorted. --- src/completion.c | 34 ++++++++++++++++++---------------- src/ex.c | 12 +++--------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/completion.c b/src/completion.c index d90ed17..a15b081 100644 --- a/src/completion.c +++ b/src/completion.c @@ -174,24 +174,26 @@ gboolean completion_next(gboolean back) rows = gtk_tree_model_iter_n_children(gtk_tree_view_get_model(tree), NULL); if (back) { - /* step back */ - if (--comp.active < 0) { - if (comp.active == -1) { - gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(GTK_TREE_VIEW(comp.tree))); - return false; - } else { - comp.active = rows - 1; - } + comp.active--; + /* Step back over the beginning. */ + if (comp.active == -1) { + /* Unselect the current item to show the user that the shown + * content is the initial typed content. */ + gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(GTK_TREE_VIEW(comp.tree))); + + return false; + } else if (comp.active < -1) { + comp.active = rows - 1; } } else { - /* step forward */ - if (++comp.active >= rows) { - if (comp.active == rows) { - gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(GTK_TREE_VIEW(comp.tree))); - return false; - } else { - comp.active = 0; - } + comp.active++; + /* Step over the end. */ + if (comp.active == rows) { + gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(GTK_TREE_VIEW(comp.tree))); + + return false; + } else if (comp.active >= rows) { + comp.active = 0; } } diff --git a/src/ex.c b/src/ex.c index e3e4281..bfbe418 100644 --- a/src/ex.c +++ b/src/ex.c @@ -1089,7 +1089,7 @@ static gboolean complete(short direction) char *input; /* input read from inputbox */ const char *in; /* pointer to input that we move */ gboolean found = false; - gboolean sort = false; + gboolean sort = true; GtkListStore *store; /* if direction is 0 stop the completion */ @@ -1170,43 +1170,37 @@ static gboolean complete(short direction) } else { found = history_fill_completion(store, HISTORY_URL, token); } + sort = false; break; case EX_SET: - sort = true; found = setting_fill_completion(store, token); break; case EX_BMA: - sort = true; found = bookmark_fill_tag_completion(store, token); break; case EX_SCR: - sort = true; found = shortcut_fill_completion(store, token); break; case EX_HANDREM: - sort = true; found = handler_fill_completion(store, token); break; #ifdef FEATURE_AUTOCMD case EX_AUTOCMD: - sort = true; found = autocmd_fill_event_completion(store, token); break; case EX_AUGROUP: - sort = true; found = autocmd_fill_group_completion(store, token); break; #endif case EX_SAVE: case EX_SOURCE: - sort = true; found = util_filename_fill_completion(store, token); break; @@ -1225,6 +1219,7 @@ static gboolean complete(short direction) if (ex_fill_completion(store, in)) { OVERWRITE_STRING(excomp.prefix, ":"); found = true; + sort = false; } } free_cmdarg(arg); @@ -1232,7 +1227,6 @@ static gboolean complete(short direction) if (history_fill_completion(store, HISTORY_SEARCH, in + 1)) { OVERWRITE_STRING(excomp.token, in + 1); OVERWRITE_NSTRING(excomp.prefix, in, 1); - sort = true; found = true; } } -- 2.20.1