mirror of
https://github.com/neovim/neovim.git
synced 2025-09-18 17:28:23 +00:00
refactor: make wildmenu code closer to Vim (#19870)
This is a small refactor that makes `compl_match_array` static and doesn't change any behavior.
This commit is contained in:
@@ -57,7 +57,7 @@ static int cmd_showtail; ///< Only show path tail in lists ?
|
|||||||
|
|
||||||
/// "compl_match_array" points the currently displayed list of entries in the
|
/// "compl_match_array" points the currently displayed list of entries in the
|
||||||
/// popup menu. It is NULL when there is no popup menu.
|
/// popup menu. It is NULL when there is no popup menu.
|
||||||
pumitem_T *compl_match_array = NULL; // TODO(zeertzjq): make this static in cmdexpand.c
|
static pumitem_T *compl_match_array = NULL;
|
||||||
static int compl_match_arraysize;
|
static int compl_match_arraysize;
|
||||||
/// First column in cmdline of the matched item for completion.
|
/// First column in cmdline of the matched item for completion.
|
||||||
static int compl_startcol;
|
static int compl_startcol;
|
||||||
@@ -256,6 +256,19 @@ void cmdline_pum_display(bool changed_array)
|
|||||||
changed_array, compl_startcol);
|
changed_array, compl_startcol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cmdline_pum_active(void)
|
||||||
|
{
|
||||||
|
// return p_wmnu && pum_visible() && compl_match_array != NULL;
|
||||||
|
return compl_match_array != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Remove the cmdline completion popup menu
|
||||||
|
void cmdline_pum_remove(void)
|
||||||
|
{
|
||||||
|
pum_undisplay(true);
|
||||||
|
XFREE_CLEAR(compl_match_array);
|
||||||
|
}
|
||||||
|
|
||||||
/// Do wildcard expansion on the string 'str'.
|
/// Do wildcard expansion on the string 'str'.
|
||||||
/// Chars that should not be expanded must be preceded with a backslash.
|
/// Chars that should not be expanded must be preceded with a backslash.
|
||||||
/// Return a pointer to allocated memory containing the new string.
|
/// Return a pointer to allocated memory containing the new string.
|
||||||
@@ -545,10 +558,14 @@ int showmatches(expand_T *xp, int wildmenu)
|
|||||||
if (compl_use_pum) {
|
if (compl_use_pum) {
|
||||||
assert(num_files >= 0);
|
assert(num_files >= 0);
|
||||||
compl_match_arraysize = num_files;
|
compl_match_arraysize = num_files;
|
||||||
compl_match_array = xcalloc((size_t)compl_match_arraysize,
|
compl_match_array = xmalloc(sizeof(pumitem_T) * (size_t)compl_match_arraysize);
|
||||||
sizeof(pumitem_T));
|
|
||||||
for (i = 0; i < num_files; i++) {
|
for (i = 0; i < num_files; i++) {
|
||||||
compl_match_array[i].pum_text = (char_u *)L_SHOWFILE(i);
|
compl_match_array[i] = (pumitem_T){
|
||||||
|
.pum_text = (char_u *)L_SHOWFILE(i),
|
||||||
|
.pum_info = NULL,
|
||||||
|
.pum_extra = NULL,
|
||||||
|
.pum_kind = NULL,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
char_u *endpos = (char_u *)(showtail ? sm_gettail(xp->xp_pattern, true) : xp->xp_pattern);
|
char_u *endpos = (char_u *)(showtail ? sm_gettail(xp->xp_pattern, true) : xp->xp_pattern);
|
||||||
if (ui_has(kUICmdline)) {
|
if (ui_has(kUICmdline)) {
|
||||||
@@ -2514,15 +2531,16 @@ int wildmenu_translate_key(CmdlineInfo *cclp, int key, expand_T *xp, int did_wil
|
|||||||
{
|
{
|
||||||
int c = key;
|
int c = key;
|
||||||
|
|
||||||
if (did_wild_list && p_wmnu) {
|
if (did_wild_list) {
|
||||||
if (c == K_LEFT) {
|
if (c == K_LEFT) {
|
||||||
c = Ctrl_P;
|
c = Ctrl_P;
|
||||||
} else if (c == K_RIGHT) {
|
} else if (c == K_RIGHT) {
|
||||||
c = Ctrl_N;
|
c = Ctrl_N;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hitting CR after "emenu Name.": complete submenu
|
// Hitting CR after "emenu Name.": complete submenu
|
||||||
if (xp->xp_context == EXPAND_MENUNAMES && p_wmnu
|
if (xp->xp_context == EXPAND_MENUNAMES
|
||||||
&& cclp->cmdpos > 1
|
&& cclp->cmdpos > 1
|
||||||
&& cclp->cmdbuff[cclp->cmdpos - 1] == '.'
|
&& cclp->cmdbuff[cclp->cmdpos - 1] == '.'
|
||||||
&& cclp->cmdbuff[cclp->cmdpos - 2] != '\\'
|
&& cclp->cmdbuff[cclp->cmdpos - 2] != '\\'
|
||||||
@@ -2548,10 +2566,6 @@ int wildmenu_process_key(CmdlineInfo *cclp, int key, expand_T *xp)
|
|||||||
{
|
{
|
||||||
int c = key;
|
int c = key;
|
||||||
|
|
||||||
if (!p_wmnu) {
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Special translations for 'wildmenu'
|
// Special translations for 'wildmenu'
|
||||||
if (xp->xp_context == EXPAND_MENUNAMES) {
|
if (xp->xp_context == EXPAND_MENUNAMES) {
|
||||||
// Hitting <Down> after "emenu Name.": complete submenu
|
// Hitting <Down> after "emenu Name.": complete submenu
|
||||||
@@ -2696,7 +2710,7 @@ void wildmenu_cleanup(CmdlineInfo *cclp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const bool skt = KeyTyped;
|
const bool skt = KeyTyped;
|
||||||
int old_RedrawingDisabled = RedrawingDisabled;
|
const int old_RedrawingDisabled = RedrawingDisabled;
|
||||||
|
|
||||||
if (cclp->input_fn) {
|
if (cclp->input_fn) {
|
||||||
RedrawingDisabled = 0;
|
RedrawingDisabled = 0;
|
||||||
|
@@ -170,8 +170,6 @@ static Array cmdline_block = ARRAY_DICT_INIT;
|
|||||||
/// user interrupting highlight function to not interrupt command-line.
|
/// user interrupting highlight function to not interrupt command-line.
|
||||||
static bool getln_interrupted_highlight = false;
|
static bool getln_interrupted_highlight = false;
|
||||||
|
|
||||||
extern pumitem_T *compl_match_array; // TODO(zeertzjq): make this static in cmdexpand.c
|
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "ex_getln.c.generated.h"
|
# include "ex_getln.c.generated.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -1023,15 +1021,14 @@ static int command_line_execute(VimState *state, int key)
|
|||||||
s->c = Ctrl_P;
|
s->c = Ctrl_P;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->c = wildmenu_translate_key(&ccline, s->c, &s->xpc, s->did_wild_list);
|
if (p_wmnu) {
|
||||||
|
s->c = wildmenu_translate_key(&ccline, s->c, &s->xpc, s->did_wild_list);
|
||||||
|
}
|
||||||
|
|
||||||
if (compl_match_array || s->did_wild_list) {
|
if (cmdline_pum_active() || s->did_wild_list) {
|
||||||
if (s->c == Ctrl_E) {
|
if (s->c == Ctrl_E || s->c == Ctrl_Y) {
|
||||||
s->res = nextwild(&s->xpc, WILD_CANCEL, WILD_NO_BEEP,
|
const int wild_type = (s->c == Ctrl_E) ? WILD_CANCEL : WILD_APPLY;
|
||||||
s->firstc != '@');
|
s->res = nextwild(&s->xpc, wild_type, 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;
|
s->c = Ctrl_E;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1040,9 +1037,8 @@ static int command_line_execute(VimState *state, int key)
|
|||||||
if (!(s->c == p_wc && KeyTyped) && s->c != p_wcm && s->c != Ctrl_Z
|
if (!(s->c == p_wc && KeyTyped) && s->c != p_wcm && s->c != Ctrl_Z
|
||||||
&& s->c != Ctrl_N && s->c != Ctrl_P && s->c != Ctrl_A
|
&& s->c != Ctrl_N && s->c != Ctrl_P && s->c != Ctrl_A
|
||||||
&& s->c != Ctrl_L) {
|
&& s->c != Ctrl_L) {
|
||||||
if (compl_match_array) {
|
if (cmdline_pum_active()) {
|
||||||
pum_undisplay(true);
|
cmdline_pum_remove();
|
||||||
XFREE_CLEAR(compl_match_array);
|
|
||||||
}
|
}
|
||||||
if (s->xpc.xp_numfiles != -1) {
|
if (s->xpc.xp_numfiles != -1) {
|
||||||
(void)ExpandOne(&s->xpc, NULL, NULL, 0, WILD_FREE);
|
(void)ExpandOne(&s->xpc, NULL, NULL, 0, WILD_FREE);
|
||||||
@@ -1055,7 +1051,9 @@ static int command_line_execute(VimState *state, int key)
|
|||||||
wildmenu_cleanup(&ccline);
|
wildmenu_cleanup(&ccline);
|
||||||
}
|
}
|
||||||
|
|
||||||
s->c = wildmenu_process_key(&ccline, s->c, &s->xpc);
|
if (p_wmnu) {
|
||||||
|
s->c = wildmenu_process_key(&ccline, s->c, &s->xpc);
|
||||||
|
}
|
||||||
|
|
||||||
// CTRL-\ CTRL-N goes to Normal mode, CTRL-\ e prompts for an expression.
|
// CTRL-\ CTRL-N goes to Normal mode, CTRL-\ e prompts for an expression.
|
||||||
if (s->c == Ctrl_BSL) {
|
if (s->c == Ctrl_BSL) {
|
||||||
@@ -1279,8 +1277,8 @@ static int command_line_execute(VimState *state, int key)
|
|||||||
// <S-Tab> goes to last match, in a clumsy way
|
// <S-Tab> goes to last match, in a clumsy way
|
||||||
if (s->c == K_S_TAB && KeyTyped) {
|
if (s->c == K_S_TAB && KeyTyped) {
|
||||||
if (nextwild(&s->xpc, WILD_EXPAND_KEEP, 0, s->firstc != '@') == OK) {
|
if (nextwild(&s->xpc, WILD_EXPAND_KEEP, 0, s->firstc != '@') == OK) {
|
||||||
showmatches(&s->xpc, p_wmnu
|
// Trigger the popup menu when wildoptions=pum
|
||||||
&& ((wim_flags[s->wim_index] & WIM_LIST) == 0));
|
showmatches(&s->xpc, p_wmnu && ((wim_flags[s->wim_index] & WIM_LIST) == 0));
|
||||||
nextwild(&s->xpc, WILD_PREV, 0, s->firstc != '@');
|
nextwild(&s->xpc, WILD_PREV, 0, s->firstc != '@');
|
||||||
nextwild(&s->xpc, WILD_PREV, 0, s->firstc != '@');
|
nextwild(&s->xpc, WILD_PREV, 0, s->firstc != '@');
|
||||||
return command_line_changed(s);
|
return command_line_changed(s);
|
||||||
|
Reference in New Issue
Block a user