mirror of
https://github.com/neovim/neovim.git
synced 2025-10-16 06:46:07 +00:00
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:
@@ -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.
|
||||
/// Returns EXPAND_NOTHING when the character that triggered expansion should
|
||||
/// 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();
|
||||
int numMatches;
|
||||
char **matches;
|
||||
int j;
|
||||
int maxlen;
|
||||
int lines;
|
||||
int columns;
|
||||
@@ -1109,12 +1108,12 @@ int showmatches(expand_T *xp, bool wildmenu)
|
||||
if (xp->xp_context == EXPAND_LUA) {
|
||||
nlua_expand_pat(xp);
|
||||
}
|
||||
int i = expand_cmdline(xp, ccline->cmdbuff, ccline->cmdpos,
|
||||
int retval = expand_cmdline(xp, ccline->cmdbuff, ccline->cmdpos,
|
||||
&numMatches, &matches);
|
||||
showtail = expand_showtail(xp);
|
||||
if (i != EXPAND_OK) {
|
||||
return i;
|
||||
if (retval != EXPAND_OK) {
|
||||
return retval;
|
||||
}
|
||||
showtail = expand_showtail(xp);
|
||||
} else {
|
||||
numMatches = xp->xp_numfiles;
|
||||
matches = xp->xp_files;
|
||||
@@ -1145,15 +1144,16 @@ int showmatches(expand_T *xp, bool wildmenu)
|
||||
// find the length of the longest file name
|
||||
maxlen = 0;
|
||||
for (int i = 0; i < numMatches; i++) {
|
||||
int len;
|
||||
if (!showtail && (xp->xp_context == EXPAND_FILES
|
||||
|| xp->xp_context == EXPAND_SHELLCMD
|
||||
|| xp->xp_context == EXPAND_BUFFERS)) {
|
||||
home_replace(NULL, matches[i], NameBuff, MAXPATHL, true);
|
||||
j = vim_strsize(NameBuff);
|
||||
len = vim_strsize(NameBuff);
|
||||
} 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) {
|
||||
|
@@ -1120,10 +1120,12 @@ static int command_line_wildchar_complete(CommandLineState *s)
|
||||
{
|
||||
int res;
|
||||
int options = WILD_NO_BEEP;
|
||||
bool noselect = (wim_flags[0] & kOptWimFlagNoselect) != 0;
|
||||
|
||||
if (wim_flags[s->wim_index] & kOptWimFlagLastused) {
|
||||
options |= WILD_BUFLASTUSED;
|
||||
}
|
||||
if (wim_flags[0] & kOptWimFlagNoselect) {
|
||||
if (noselect) {
|
||||
options |= WILD_KEEP_SOLE_ITEM;
|
||||
}
|
||||
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
|
||||
&& ((wim_flags[s->wim_index] & kOptWimFlagList)
|
||||
|| (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();
|
||||
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 all matches
|
||||
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
|
||||
// "list:longest")
|
||||
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;
|
||||
}
|
||||
|
||||
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();
|
||||
s->did_wild_list = true;
|
||||
|
||||
@@ -1469,7 +1475,9 @@ static int command_line_execute(VimState *state, int key)
|
||||
if (s->xpc.xp_numfiles > 1
|
||||
&& ((!s->did_wild_list && (wim_flags[s->wim_index] & kOptWimFlagList)) || p_wmnu)) {
|
||||
// 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 != '@');
|
||||
@@ -2036,7 +2044,8 @@ static int command_line_handle_key(CommandLineState *s)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user