mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 22:18:33 +00:00
vim-patch:9.0.2037: A few remaining cmdline completion issues with C-E/Y (#25686)
Problem: A few remaining cmdline completion issues with C-E/Y
Solution: Fix cmdline completion fuzzy/Ctrl-E/Ctrl-Y/options when not
used at the end
Fix cmdline completion fuzzy/Ctrl-E/Ctrl-Y/options when not used at the end
A few places in the cmdline completion code only works properly when the
user hits Tab (or 'wildchar') at the end of the cmdline, even though
it's supposed to work even in the middle of the line.
For fuzzy search, `:e ++ff`, and `:set hl=`, fix completion code to make
sure to use `xp_pattern_len` instead of assuming the entire `xp_pattern`
is the search pattern (since it contains texts after the cursor).
Fix Ctrl-E / Ctrl-Y to not jump to the end when canceling/accepting a
wildmenu completion. Also, make them work even when not using
`set wildoptions+=pum` as there is no drawback to doing so.
(Related issue where this was brought up: vim/vim#13331)
closes: vim/vim#13362
209ec90b9b
Cherry-pick ex_getln.c changes from patch 9.0.2035.
Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
This commit is contained in:
@@ -861,6 +861,16 @@ static uint8_t *command_line_enter(int firstc, int count, int indent, bool clear
|
||||
|
||||
cmdmsg_rl = false;
|
||||
|
||||
// We could have reached here without having a chance to clean up wild menu
|
||||
// if certain special keys like <Esc> or <C-\> were used as wildchar. Make
|
||||
// sure to still clean up to avoid memory corruption.
|
||||
if (cmdline_pum_active()) {
|
||||
cmdline_pum_remove();
|
||||
}
|
||||
wildmenu_cleanup(&ccline);
|
||||
s->did_wild_list = false;
|
||||
s->wim_index = 0;
|
||||
|
||||
ExpandCleanup(&s->xpc);
|
||||
ccline.xpc = NULL;
|
||||
|
||||
@@ -1247,13 +1257,14 @@ static int command_line_execute(VimState *state, int key)
|
||||
s->c = wildmenu_translate_key(&ccline, s->c, &s->xpc, s->did_wild_list);
|
||||
}
|
||||
|
||||
if (cmdline_pum_active() || s->did_wild_list) {
|
||||
int wild_type = 0;
|
||||
const bool key_is_wc = (s->c == p_wc && KeyTyped) || s->c == p_wcm;
|
||||
if ((cmdline_pum_active() || s->did_wild_list) && !key_is_wc) {
|
||||
// Ctrl-Y: Accept the current selection and close the popup menu.
|
||||
// Ctrl-E: cancel the cmdline popup menu and return the original text.
|
||||
if (s->c == Ctrl_E || s->c == Ctrl_Y) {
|
||||
const int wild_type = (s->c == Ctrl_E) ? WILD_CANCEL : WILD_APPLY;
|
||||
wild_type = (s->c == Ctrl_E) ? WILD_CANCEL : WILD_APPLY;
|
||||
(void)nextwild(&s->xpc, wild_type, WILD_NO_BEEP, s->firstc != '@');
|
||||
s->c = Ctrl_E;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1262,7 +1273,7 @@ static int command_line_execute(VimState *state, int key)
|
||||
// 'wildcharm' or Ctrl-N or Ctrl-P or Ctrl-A or Ctrl-L).
|
||||
// If the popup menu is displayed, then PageDown and PageUp keys are
|
||||
// also used to navigate the menu.
|
||||
bool end_wildmenu = (!(s->c == p_wc && KeyTyped) && s->c != p_wcm && s->c != Ctrl_Z
|
||||
bool end_wildmenu = (!key_is_wc && s->c != Ctrl_Z
|
||||
&& s->c != Ctrl_N && s->c != Ctrl_P && s->c != Ctrl_A
|
||||
&& s->c != Ctrl_L);
|
||||
end_wildmenu = end_wildmenu && (!cmdline_pum_active()
|
||||
@@ -1366,6 +1377,12 @@ static int command_line_execute(VimState *state, int key)
|
||||
}
|
||||
|
||||
s->do_abbr = true; // default: check for abbreviation
|
||||
|
||||
// If already used to cancel/accept wildmenu, don't process the key further.
|
||||
if (wild_type == WILD_CANCEL || wild_type == WILD_APPLY) {
|
||||
return command_line_not_changed(s);
|
||||
}
|
||||
|
||||
return command_line_handle_key(s);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user