vim-patch:partial:9.1.1639: completion: popup may be misplaced

Problem:  During commandline completiom, popup window placement can be
          incorrect when 'noselect' is present in 'wildmode'
          (Shane-XB-Qian)
Solution: Disable "showtail" feature when 'noselect' is present.

fixes: vim/vim#17969
closes: vim/vim#18001

1e38198a41

Partial port excluding the showtail change and the test.

Co-authored-by: Girish Palya <girishji@gmail.com>
This commit is contained in:
zeertzjq
2025-08-24 18:50:22 +08:00
parent ad22d0ace9
commit a16064ff29
2 changed files with 25 additions and 16 deletions

View File

@@ -1087,12 +1087,11 @@ static void showmatches_oneline(expand_T *xp, char **matches, int numMatches, in
/// Show all matches for completion on the command line. /// Show all matches for completion on the command line.
/// Returns EXPAND_NOTHING when the character that triggered expansion should /// Returns EXPAND_NOTHING when the character that triggered expansion should
/// be inserted like a normal character. /// be inserted like a normal character.
int showmatches(expand_T *xp, bool wildmenu) int showmatches(expand_T *xp, bool wildmenu, bool noselect)
{ {
CmdlineInfo *const ccline = get_cmdline_info(); CmdlineInfo *const ccline = get_cmdline_info();
int numMatches; int numMatches;
char **matches; char **matches;
int j;
int maxlen; int maxlen;
int lines; int lines;
int columns; int columns;
@@ -1109,12 +1108,12 @@ int showmatches(expand_T *xp, bool wildmenu)
if (xp->xp_context == EXPAND_LUA) { if (xp->xp_context == EXPAND_LUA) {
nlua_expand_pat(xp); nlua_expand_pat(xp);
} }
int i = expand_cmdline(xp, ccline->cmdbuff, ccline->cmdpos, int retval = expand_cmdline(xp, ccline->cmdbuff, ccline->cmdpos,
&numMatches, &matches); &numMatches, &matches);
showtail = expand_showtail(xp); if (retval != EXPAND_OK) {
if (i != EXPAND_OK) { return retval;
return i;
} }
showtail = expand_showtail(xp);
} else { } else {
numMatches = xp->xp_numfiles; numMatches = xp->xp_numfiles;
matches = xp->xp_files; matches = xp->xp_files;
@@ -1145,15 +1144,16 @@ int showmatches(expand_T *xp, bool wildmenu)
// find the length of the longest file name // find the length of the longest file name
maxlen = 0; maxlen = 0;
for (int i = 0; i < numMatches; i++) { for (int i = 0; i < numMatches; i++) {
int len;
if (!showtail && (xp->xp_context == EXPAND_FILES if (!showtail && (xp->xp_context == EXPAND_FILES
|| xp->xp_context == EXPAND_SHELLCMD || xp->xp_context == EXPAND_SHELLCMD
|| xp->xp_context == EXPAND_BUFFERS)) { || xp->xp_context == EXPAND_BUFFERS)) {
home_replace(NULL, matches[i], NameBuff, MAXPATHL, true); home_replace(NULL, matches[i], NameBuff, MAXPATHL, true);
j = vim_strsize(NameBuff); len = vim_strsize(NameBuff);
} else { } else {
j = vim_strsize(SHOW_MATCH(i)); len = vim_strsize(SHOW_MATCH(i));
} }
maxlen = MAX(maxlen, j); maxlen = MAX(maxlen, len);
} }
if (xp->xp_context == EXPAND_TAGS_LISTFILES) { if (xp->xp_context == EXPAND_TAGS_LISTFILES) {

View File

@@ -1120,10 +1120,12 @@ static int command_line_wildchar_complete(CommandLineState *s)
{ {
int res; int res;
int options = WILD_NO_BEEP; int options = WILD_NO_BEEP;
bool noselect = (wim_flags[0] & kOptWimFlagNoselect) != 0;
if (wim_flags[s->wim_index] & kOptWimFlagLastused) { if (wim_flags[s->wim_index] & kOptWimFlagLastused) {
options |= WILD_BUFLASTUSED; options |= WILD_BUFLASTUSED;
} }
if (wim_flags[0] & kOptWimFlagNoselect) { if (noselect) {
options |= WILD_KEEP_SOLE_ITEM; options |= WILD_KEEP_SOLE_ITEM;
} }
if (s->xpc.xp_numfiles > 0) { // typed p_wc at least twice if (s->xpc.xp_numfiles > 0) { // typed p_wc at least twice
@@ -1132,7 +1134,9 @@ static int command_line_wildchar_complete(CommandLineState *s)
&& !s->did_wild_list && !s->did_wild_list
&& ((wim_flags[s->wim_index] & kOptWimFlagList) && ((wim_flags[s->wim_index] & kOptWimFlagList)
|| (p_wmnu && (wim_flags[s->wim_index] & kOptWimFlagFull) != 0))) { || (p_wmnu && (wim_flags[s->wim_index] & kOptWimFlagFull) != 0))) {
showmatches(&s->xpc, p_wmnu && ((wim_flags[s->wim_index] & kOptWimFlagList) == 0)); showmatches(&s->xpc,
p_wmnu && ((wim_flags[s->wim_index] & kOptWimFlagList) == 0),
noselect);
redrawcmd(); redrawcmd();
s->did_wild_list = true; s->did_wild_list = true;
} }
@@ -1176,7 +1180,7 @@ static int command_line_wildchar_complete(CommandLineState *s)
// "list", or no change and 'wildmode' contains "longest,list", // "list", or no change and 'wildmode' contains "longest,list",
// list all matches // list all matches
if (res == OK if (res == OK
&& s->xpc.xp_numfiles > ((wim_flags[s->wim_index] & kOptWimFlagNoselect) ? 0 : 1)) { && s->xpc.xp_numfiles > (noselect ? 0 : 1)) {
// a "longest" that didn't do anything is skipped (but not // a "longest" that didn't do anything is skipped (but not
// "list:longest") // "list:longest")
if (wim_flags[0] == kOptWimFlagLongest && ccline.cmdpos == j) { if (wim_flags[0] == kOptWimFlagLongest && ccline.cmdpos == j) {
@@ -1192,7 +1196,9 @@ static int command_line_wildchar_complete(CommandLineState *s)
p_wmnu = p_wmnu_save; p_wmnu = p_wmnu_save;
} }
showmatches(&s->xpc, p_wmnu && ((wim_flags[s->wim_index] & kOptWimFlagList) == 0)); showmatches(&s->xpc,
p_wmnu && ((wim_flags[s->wim_index] & kOptWimFlagList) == 0),
noselect);
redrawcmd(); redrawcmd();
s->did_wild_list = true; s->did_wild_list = true;
@@ -1469,7 +1475,9 @@ static int command_line_execute(VimState *state, int key)
if (s->xpc.xp_numfiles > 1 if (s->xpc.xp_numfiles > 1
&& ((!s->did_wild_list && (wim_flags[s->wim_index] & kOptWimFlagList)) || p_wmnu)) { && ((!s->did_wild_list && (wim_flags[s->wim_index] & kOptWimFlagList)) || p_wmnu)) {
// Trigger the popup menu when wildoptions=pum // Trigger the popup menu when wildoptions=pum
showmatches(&s->xpc, p_wmnu && ((wim_flags[s->wim_index] & kOptWimFlagList) == 0)); showmatches(&s->xpc,
p_wmnu && ((wim_flags[s->wim_index] & kOptWimFlagList) == 0),
wim_flags[0] & kOptWimFlagNoselect);
} }
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 != '@');
@@ -2036,7 +2044,8 @@ static int command_line_handle_key(CommandLineState *s)
} }
case Ctrl_D: case Ctrl_D:
if (showmatches(&s->xpc, false) == EXPAND_NOTHING) { if (showmatches(&s->xpc, false, wim_flags[0] & kOptWimFlagNoselect)
== EXPAND_NOTHING) {
break; // Use ^D as normal char instead break; // Use ^D as normal char instead
} }