diff options
author | Matthieu Coudron <mattator@gmail.com> | 2020-03-28 14:25:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-28 14:25:54 +0100 |
commit | e700a88bb6bdc96f4d62a384aecd3bec2040ac3b (patch) | |
tree | 3d6792e4b690cf00a93861aa7d7fd9d90ba61f8e | |
parent | a8f784192404864744c323e4394292467c3c0ca7 (diff) | |
parent | 4d53bdccc60a4bc39e6ca2c626f4b511881559ef (diff) | |
download | rneovim-e700a88bb6bdc96f4d62a384aecd3bec2040ac3b.tar.gz rneovim-e700a88bb6bdc96f4d62a384aecd3bec2040ac3b.tar.bz2 rneovim-e700a88bb6bdc96f4d62a384aecd3bec2040ac3b.zip |
Merge pull request #11746 from Billy4195/add_wildmenu_key
[RFC] Wildmenu support C-E and C-Y as popupmenu
-rw-r--r-- | runtime/doc/options.txt | 4 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 18 | ||||
-rw-r--r-- | src/nvim/ex_getln.h | 2 | ||||
-rw-r--r-- | test/functional/ui/wildmode_spec.lua | 38 |
4 files changed, 61 insertions, 1 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 06977ac454..5fb80d75ce 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -6701,6 +6701,10 @@ A jump table for the options with a short description can be found at |Q_op|. While the menu is active these keys have special meanings: + CTRL-Y - accept the currently selected match and stop + completion. + CTRL-E - end completion, go back to what was there before + selecting a match. <Left> <Right> - select previous/next match (like CTRL-P/CTRL-N) <Down> - in filename/menu name completion: move into a subdirectory or submenu. diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index c9f36ccd61..0c28f2ae70 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -621,6 +621,16 @@ static int command_line_execute(VimState *state, int key) s->c = Ctrl_N; } } + if (compl_match_array || s->did_wild_list) { + if (s->c == Ctrl_E) { + s->res = nextwild(&s->xpc, WILD_CANCEL, WILD_NO_BEEP, + s->firstc != '@'); + } else if (s->c == Ctrl_Y) { + s->res = nextwild(&s->xpc, WILD_APPLY, WILD_NO_BEEP, + s->firstc != '@'); + s->c = Ctrl_E; + } + } // Hitting CR after "emenu Name.": complete submenu if (s->xpc.xp_context == EXPAND_MENUNAMES && p_wmnu @@ -3790,6 +3800,12 @@ ExpandOne ( return NULL; } + if (mode == WILD_CANCEL) { + ss = vim_strsave(orig_save); + } else if (mode == WILD_APPLY) { + ss = vim_strsave(findex == -1 ? orig_save : xp->xp_files[findex]); + } + /* free old names */ if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) { FreeWild(xp->xp_numfiles, xp->xp_files); @@ -3801,7 +3817,7 @@ ExpandOne ( if (mode == WILD_FREE) /* only release file name */ return NULL; - if (xp->xp_numfiles == -1) { + if (xp->xp_numfiles == -1 && mode != WILD_APPLY && mode != WILD_CANCEL) { xfree(orig_save); orig_save = orig; orig_saved = TRUE; diff --git a/src/nvim/ex_getln.h b/src/nvim/ex_getln.h index 99d5a7786d..84b2b41f30 100644 --- a/src/nvim/ex_getln.h +++ b/src/nvim/ex_getln.h @@ -16,6 +16,8 @@ #define WILD_ALL 6 #define WILD_LONGEST 7 #define WILD_ALL_KEEP 8 +#define WILD_CANCEL 9 +#define WILD_APPLY 10 #define WILD_LIST_NOTFOUND 0x01 #define WILD_HOME_REPLACE 0x02 diff --git a/test/functional/ui/wildmode_spec.lua b/test/functional/ui/wildmode_spec.lua index 56987d7bc2..99ebc4971e 100644 --- a/test/functional/ui/wildmode_spec.lua +++ b/test/functional/ui/wildmode_spec.lua @@ -16,6 +16,44 @@ describe("'wildmenu'", function() screen:attach() end) + it('C-E to cancel wildmenu completion restore original input', function() + feed(':sign <tab>') + screen:expect([[ + | + ~ | + ~ | + define jump list > | + :sign define^ | + ]]) + feed('<C-E>') + screen:expect([[ + | + ~ | + ~ | + ~ | + :sign ^ | + ]]) + end) + + it('C-Y to apply selection and end wildmenu completion', function() + feed(':sign <tab>') + screen:expect([[ + | + ~ | + ~ | + define jump list > | + :sign define^ | + ]]) + feed('<tab><C-Y>') + screen:expect([[ + | + ~ | + ~ | + ~ | + :sign jump^ | + ]]) + end) + it(':sign <tab> shows wildmenu completions', function() command('set wildmenu wildmode=full') feed(':sign <tab>') |