patch 9.1.1714: completion: wildmode=longest:full selects wrong item
Problem: completion: wildmode=longest:full selects wrong item
(zeertzjq)
Solution: Fix issue, refactor ex_getln.c slightly
(Girish Palya)
fixes: #18102
closes: #18125
Signed-off-by: Girish Palya <girishji@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
5355e81868
commit
2eccb4d0be
@ -944,23 +944,20 @@ cmdline_wildchar_complete(
|
||||
{
|
||||
int wim_index = *wim_index_p;
|
||||
int res;
|
||||
int j;
|
||||
int cmdpos_before;
|
||||
int options = WILD_NO_BEEP;
|
||||
int noselect = p_wmnu && (wim_flags[0] & WIM_NOSELECT);
|
||||
int wim_noselect = p_wmnu && (wim_flags[0] & WIM_NOSELECT);
|
||||
|
||||
if (wim_flags[wim_index] & WIM_BUFLASTUSED)
|
||||
options |= WILD_BUFLASTUSED;
|
||||
if (xp->xp_numfiles > 0) // typed p_wc at least twice
|
||||
{
|
||||
// if 'wildmode' contains "list" may still need to list
|
||||
// If "list" is present, list matches unless already listed
|
||||
if (xp->xp_numfiles > 1
|
||||
&& !*did_wild_list
|
||||
&& ((wim_flags[wim_index] & WIM_LIST)
|
||||
|| (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0)))
|
||||
&& (wim_flags[wim_index] & WIM_LIST))
|
||||
{
|
||||
(void)showmatches(xp,
|
||||
p_wmnu && ((wim_flags[wim_index] & WIM_LIST) == 0),
|
||||
noselect);
|
||||
(void)showmatches(xp, FALSE, TRUE, wim_noselect);
|
||||
redrawcmd();
|
||||
*did_wild_list = TRUE;
|
||||
}
|
||||
@ -973,6 +970,11 @@ cmdline_wildchar_complete(
|
||||
}
|
||||
else // typed p_wc first time
|
||||
{
|
||||
int wim_longest = (wim_flags[0] & WIM_LONGEST);
|
||||
int wim_list = (wim_flags[0] & WIM_LIST);
|
||||
int wim_full = (wim_flags[0] & WIM_FULL);
|
||||
|
||||
wim_index = 0;
|
||||
if (c == p_wc || c == p_wcm || c == K_WILD)
|
||||
{
|
||||
options |= WILD_MAY_EXPAND_PATTERN;
|
||||
@ -983,15 +985,15 @@ cmdline_wildchar_complete(
|
||||
else
|
||||
xp->xp_pre_incsearch_pos = curwin->w_cursor;
|
||||
}
|
||||
wim_index = 0;
|
||||
j = ccline.cmdpos;
|
||||
cmdpos_before = ccline.cmdpos;
|
||||
|
||||
// if 'wildmode' first contains "longest", get longest
|
||||
// common part
|
||||
if (wim_flags[0] & WIM_LONGEST)
|
||||
if (wim_longest)
|
||||
res = nextwild(xp, WILD_LONGEST, options, escape);
|
||||
else
|
||||
{
|
||||
if (noselect || (wim_flags[wim_index] & WIM_LIST))
|
||||
if (wim_noselect || wim_list)
|
||||
options |= WILD_NOSELECT;
|
||||
res = nextwild(xp, WILD_EXPAND_KEEP, options, escape);
|
||||
}
|
||||
@ -1011,28 +1013,29 @@ cmdline_wildchar_complete(
|
||||
return CMDLINE_CHANGED;
|
||||
}
|
||||
|
||||
// when more than one match, and 'wildmode' first contains
|
||||
// "list", or no change and 'wildmode' contains "longest,list",
|
||||
// list all matches
|
||||
if (res == OK
|
||||
&& xp->xp_numfiles > (noselect ? 0 : 1))
|
||||
// Display matches
|
||||
if (res == OK && xp->xp_numfiles > (wim_noselect ? 0 : 1))
|
||||
{
|
||||
// a "longest" that didn't do anything is skipped (but not
|
||||
// "list:longest")
|
||||
if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j)
|
||||
wim_index = 1;
|
||||
if ((wim_flags[wim_index] & WIM_LIST)
|
||||
|| (p_wmnu && (wim_flags[wim_index] & (WIM_FULL | WIM_NOSELECT))))
|
||||
// If "longest" fails to identify the longest item, try other
|
||||
// 'wim' values if available
|
||||
if (wim_longest && ccline.cmdpos == cmdpos_before)
|
||||
{
|
||||
(void)showmatches(xp, p_wmnu
|
||||
&& ((wim_flags[wim_index] & WIM_LIST) == 0), noselect);
|
||||
redrawcmd();
|
||||
*did_wild_list = TRUE;
|
||||
if (wim_flags[wim_index] & WIM_LONGEST)
|
||||
nextwild(xp, WILD_LONGEST, options, escape);
|
||||
if (wim_full)
|
||||
nextwild(xp, WILD_NEXT, options, escape);
|
||||
if (wim_list || (p_wmnu && wim_full))
|
||||
(void)showmatches(xp, p_wmnu, wim_list, FALSE);
|
||||
}
|
||||
else
|
||||
vim_beep(BO_WILD);
|
||||
else if (!wim_longest)
|
||||
{
|
||||
if (wim_list || (p_wmnu && (wim_full || wim_noselect)))
|
||||
(void)showmatches(xp, p_wmnu, wim_list, wim_noselect);
|
||||
else
|
||||
vim_beep(BO_WILD);
|
||||
}
|
||||
|
||||
redrawcmd();
|
||||
if (wim_list)
|
||||
*did_wild_list = TRUE;
|
||||
}
|
||||
else if (xp->xp_numfiles == -1)
|
||||
xp->xp_context = EXPAND_NOTHING;
|
||||
@ -1959,7 +1962,8 @@ getcmdline_int(
|
||||
c = wildmenu_translate_key(&ccline, c, &xpc, did_wild_list);
|
||||
|
||||
int key_is_wc = (c == p_wc && KeyTyped) || c == p_wcm;
|
||||
if ((cmdline_pum_active() || did_wild_list) && !key_is_wc)
|
||||
if ((cmdline_pum_active() || wild_menu_showing || 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
|
||||
@ -2118,8 +2122,7 @@ getcmdline_int(
|
||||
|| p_wmnu))
|
||||
{
|
||||
// Trigger the popup menu when wildoptions=pum
|
||||
showmatches(&xpc, p_wmnu
|
||||
&& ((wim_flags[wim_index] & WIM_LIST) == 0),
|
||||
showmatches(&xpc, p_wmnu, wim_flags[wim_index] & WIM_LIST,
|
||||
wim_flags[0] & WIM_NOSELECT);
|
||||
}
|
||||
if (nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK
|
||||
@ -2235,7 +2238,7 @@ getcmdline_int(
|
||||
goto cmdline_not_changed;
|
||||
|
||||
case Ctrl_D:
|
||||
if (showmatches(&xpc, FALSE, wim_flags[0] & WIM_NOSELECT)
|
||||
if (showmatches(&xpc, FALSE, TRUE, wim_flags[0] & WIM_NOSELECT)
|
||||
== EXPAND_NOTHING)
|
||||
break; // Use ^D as normal char instead
|
||||
|
||||
|
||||
Reference in New Issue
Block a user