Skip to content

Commit 5737930

Browse files
girishjichrisbra
authored andcommitted
patch 9.1.1676: completion: long line shown twice
Problem: completion: long line shown twice (Maxim Kim) Solution: Fix the issue, disable an incorrect test. (Girish Palya) fixes: #18035 closes: #18088 Signed-off-by: Girish Palya <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent e06d81f commit 5737930

File tree

8 files changed

+86
-41
lines changed

8 files changed

+86
-41
lines changed

src/cmdexpand.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ nextwild(
239239
int i;
240240
char_u *p;
241241
int from_wildtrigger_func = options & WILD_FUNC_TRIGGER;
242+
int wild_navigate = (type == WILD_NEXT || type == WILD_PREV
243+
|| type == WILD_PAGEUP || type == WILD_PAGEDOWN);
242244

243245
if (xp->xp_numfiles == -1)
244246
{
@@ -280,14 +282,13 @@ nextwild(
280282

281283
// If cmd_silent is set then don't show the dots, because redrawcmd() below
282284
// won't remove them.
283-
if (!cmd_silent && !from_wildtrigger_func)
285+
if (!cmd_silent && !from_wildtrigger_func && !wild_navigate)
284286
{
285287
msg_puts("..."); // show that we are busy
286288
out_flush();
287289
}
288290

289-
if (type == WILD_NEXT || type == WILD_PREV
290-
|| type == WILD_PAGEUP || type == WILD_PAGEDOWN)
291+
if (wild_navigate)
291292
{
292293
// Get next/previous match for a previous expanded pattern.
293294
p = ExpandOne(xp, NULL, NULL, 0, type);
@@ -310,8 +311,6 @@ nextwild(
310311
{
311312
int use_options = options |
312313
WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT;
313-
if (use_options & WILD_KEEP_SOLE_ITEM)
314-
use_options &= ~WILD_KEEP_SOLE_ITEM;
315314
if (escape)
316315
use_options |= WILD_ESCAPE;
317316
if (p_wic)
@@ -338,7 +337,14 @@ nextwild(
338337
}
339338
}
340339

341-
if (p != NULL && !got_int)
340+
// Save cmdline before inserting selected item
341+
if (!wild_navigate && ccline->cmdbuff != NULL)
342+
{
343+
vim_free(cmdline_orig);
344+
cmdline_orig = vim_strnsave(ccline->cmdbuff, ccline->cmdlen);
345+
}
346+
347+
if (p != NULL && !got_int && !(options & WILD_NOSELECT))
342348
{
343349
size_t plen = STRLEN(p);
344350
int difflen;
@@ -372,7 +378,8 @@ nextwild(
372378

373379
if (xp->xp_numfiles <= 0 && p == NULL)
374380
beep_flush();
375-
else if (xp->xp_numfiles == 1 && !(options & WILD_KEEP_SOLE_ITEM))
381+
else if (xp->xp_numfiles == 1 && !(options & WILD_NOSELECT)
382+
&& !wild_navigate)
376383
// free expanded pattern
377384
(void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE);
378385

@@ -391,7 +398,8 @@ cmdline_pum_create(
391398
expand_T *xp,
392399
char_u **matches,
393400
int numMatches,
394-
int showtail)
401+
int showtail,
402+
int noselect)
395403
{
396404
int i;
397405
int prefix_len;
@@ -421,7 +429,7 @@ cmdline_pum_create(
421429
compl_startcol = MAX(0, compl_startcol - prefix_len);
422430

423431
// no default selection
424-
compl_selected = -1;
432+
compl_selected = noselect ? -1 : 0;
425433

426434
pum_clear();
427435
cmdline_pum_display();
@@ -1072,7 +1080,7 @@ ExpandOne(
10721080
if (compl_match_array != NULL)
10731081
cmdline_pum_remove(get_cmdline_info(), FALSE);
10741082
}
1075-
xp->xp_selected = 0;
1083+
xp->xp_selected = (options & WILD_NOSELECT) ? -1 : 0;
10761084

10771085
if (mode == WILD_FREE) // only release file name
10781086
return NULL;
@@ -1288,13 +1296,6 @@ showmatches(expand_T *xp, int wildmenu, int noselect)
12881296
int attr;
12891297
int showtail;
12901298

1291-
// Save cmdline before expansion
1292-
if (ccline->cmdbuff != NULL)
1293-
{
1294-
vim_free(cmdline_orig);
1295-
cmdline_orig = vim_strnsave(ccline->cmdbuff, ccline->cmdlen);
1296-
}
1297-
12981299
if (xp->xp_numfiles == -1)
12991300
{
13001301
int retval;
@@ -1315,7 +1316,7 @@ showmatches(expand_T *xp, int wildmenu, int noselect)
13151316
if (wildmenu && vim_strchr(p_wop, WOP_PUM) != NULL)
13161317
// cmdline completion popup menu (with wildoptions=pum)
13171318
return cmdline_pum_create(ccline, xp, matches, numMatches,
1318-
showtail && !noselect);
1319+
showtail && !noselect, noselect);
13191320

13201321
if (!wildmenu)
13211322
{
@@ -1331,7 +1332,7 @@ showmatches(expand_T *xp, int wildmenu, int noselect)
13311332
if (got_int)
13321333
got_int = FALSE; // only int. the completion, not the cmd line
13331334
else if (wildmenu)
1334-
win_redr_status_matches(xp, numMatches, matches, -1, showtail);
1335+
win_redr_status_matches(xp, numMatches, matches, noselect ? -1 : 0, showtail);
13351336
else
13361337
{
13371338
// find the length of the longest file name

src/ex_getln.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -946,12 +946,10 @@ cmdline_wildchar_complete(
946946
int res;
947947
int j;
948948
int options = WILD_NO_BEEP;
949-
int noselect = (wim_flags[0] & WIM_NOSELECT) != 0;
949+
int noselect = p_wmnu && (wim_flags[0] & WIM_NOSELECT);
950950

951951
if (wim_flags[wim_index] & WIM_BUFLASTUSED)
952952
options |= WILD_BUFLASTUSED;
953-
if (noselect)
954-
options |= WILD_KEEP_SOLE_ITEM;
955953
if (xp->xp_numfiles > 0) // typed p_wc at least twice
956954
{
957955
// if 'wildmode' contains "list" may still need to list
@@ -992,7 +990,11 @@ cmdline_wildchar_complete(
992990
if (wim_flags[0] & WIM_LONGEST)
993991
res = nextwild(xp, WILD_LONGEST, options, escape);
994992
else
993+
{
994+
if (noselect || (wim_flags[wim_index] & WIM_LIST))
995+
options |= WILD_NOSELECT;
995996
res = nextwild(xp, WILD_EXPAND_KEEP, options, escape);
997+
}
996998

997999
// Remove popup window if no completion items are available
9981000
if (redraw_if_menu_empty && xp->xp_numfiles <= 0)
@@ -1022,25 +1024,12 @@ cmdline_wildchar_complete(
10221024
if ((wim_flags[wim_index] & WIM_LIST)
10231025
|| (p_wmnu && (wim_flags[wim_index] & (WIM_FULL | WIM_NOSELECT))))
10241026
{
1025-
if (!(wim_flags[0] & WIM_LONGEST))
1026-
{
1027-
int p_wmnu_save = p_wmnu;
1028-
1029-
p_wmnu = 0;
1030-
1031-
// remove match
1032-
nextwild(xp, WILD_PREV, options, escape);
1033-
p_wmnu = p_wmnu_save;
1034-
}
10351027
(void)showmatches(xp, p_wmnu
10361028
&& ((wim_flags[wim_index] & WIM_LIST) == 0), noselect);
10371029
redrawcmd();
10381030
*did_wild_list = TRUE;
10391031
if (wim_flags[wim_index] & WIM_LONGEST)
10401032
nextwild(xp, WILD_LONGEST, options, escape);
1041-
else if ((wim_flags[wim_index] & WIM_FULL)
1042-
&& !(wim_flags[wim_index] & WIM_NOSELECT))
1043-
nextwild(xp, WILD_NEXT, options, escape);
10441033
}
10451034
else
10461035
vim_beep(BO_WILD);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
| +0&#ffffff0@59
2+
|~+0#4040ff13&| @58
3+
|~| @58
4+
|~| @58
5+
|~| @58
6+
|~| @58
7+
|~| @10| +0#0000001#ffd7ff255|l|o@15|n|g| |q|u|i|t|e| |l|o@11|n|g|,| |r|e|a|l
8+
|:+0#0000000#ffffff0|D|o|u|b|l|e|E|n|t|r|y| > @46
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
|~+0#4040ff13#ffffff0| @58
2+
|~| @58
3+
|~| @58
4+
|~| @58
5+
|~| @10| +0#0000001#e0e0e08|l|o@15|n|g| |q|u|i|t|e| |l|o@11|n|g|,| |r|e|a|l
6+
|:+0#0000000#ffffff0|D|o|u|b|l|e|E|n|t|r|y| |l|o@15|n|g| |q|u|i|t|e| |l|o@11|n|g|,| |r|e|a|l
7+
@1|y| |l|o@11|n|g|,| |p|r|o|b|a|b|l|y| |t|o@1| |l|o@25
8+
@1|n|g| |e|n|t|r|y> @50
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
|~+0#4040ff13#ffffff0| @58
2+
|~| @58
3+
|~| @58
4+
|~| @58
5+
|~| @10| +0#0000001#ffd7ff255|l|o@15|n|g| |q|u|i|t|e| |l|o@11|n|g|,| |r|e|a|l
6+
|:+0#0000000#ffffff0|D|o|u|b|l|e|E|n|t|r|y| > @46
7+
@60
8+
@60

src/testdir/test_cmdline.vim

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,8 +2267,11 @@ func Wildmode_tests()
22672267
" when using longest completion match, matches shorter than the argument
22682268
" should be ignored (happens with :help)
22692269
set wildmode=longest,full
2270-
call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
2271-
call assert_equal('"help a', @:)
2270+
" XXX: This test is incorrect. ':help a*' will never yield 'help a'
2271+
" because '`a' exists as a menu item. The intent was to test a case
2272+
" handled by nextwild().
2273+
" call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
2274+
" call assert_equal('"help a', @:)
22722275
" non existing file
22732276
call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
22742277
call assert_equal('"e a1b2y3z4', @:)
@@ -4351,7 +4354,7 @@ func Test_cmdcomplete_info()
43514354
call feedkeys(":h echom\<cr>", "tx") " No expansion
43524355
call assert_equal('{}', g:cmdcomplete_info)
43534356
call feedkeys($":h echoms{trig}\<cr>", "tx")
4354-
call assert_equal('{''cmdline_orig'': '''', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info)
4357+
call assert_equal('{''cmdline_orig'': ''h echoms'', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info)
43554358
call feedkeys($":h echom{trig}\<cr>", "tx")
43564359
call assert_equal(
43574360
\ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': 0}',
@@ -4367,7 +4370,7 @@ func Test_cmdcomplete_info()
43674370

43684371
set wildoptions=pum
43694372
call feedkeys($":h echoms{trig}\<cr>", "tx")
4370-
call assert_equal('{''cmdline_orig'': '''', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info)
4373+
call assert_equal('{''cmdline_orig'': ''h echoms'', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info)
43714374
call feedkeys($":h echom{trig}\<cr>", "tx")
43724375
call assert_equal(
43734376
\ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': 0}',
@@ -4864,7 +4867,6 @@ endfunc
48644867
" file paths when 'noselect' is present.
48654868
func Test_noselect_expand_env_var()
48664869
CheckScreendump
4867-
48684870
let lines =<< trim [SCRIPT]
48694871
set wildmenu wildoptions=pum wildmode=noselect,full
48704872
let $TESTDIR = 'a/b'
@@ -4889,4 +4891,31 @@ func Test_noselect_expand_env_var()
48894891
call StopVimInTerminal(buf)
48904892
endfunc
48914893

4894+
" Issue #18035: long lines should not get listed twice in the menu when
4895+
" 'wildmode' contains 'noselect'
4896+
func Test_long_line_noselect()
4897+
CheckScreendump
4898+
let lines =<< trim [SCRIPT]
4899+
set wildmenu wildoptions=pum wildmode=noselect,full
4900+
command -nargs=1 -complete=custom,Entries DoubleEntry echo
4901+
func Entries(a, b, c)
4902+
return 'loooooooooooooooong quite loooooooooooong, really loooooooooooong, probably too looooooooooooooooooooooooooong entry'
4903+
endfunc
4904+
[SCRIPT]
4905+
call writefile(lines, 'XTest_wildmenu', 'D')
4906+
let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8, 'cols': 60})
4907+
4908+
call term_sendkeys(buf, ":DoubleEntry \<Tab>")
4909+
call VerifyScreenDump(buf, 'Test_long_line_noselect_1', {})
4910+
4911+
call term_sendkeys(buf, "\<Esc>:DoubleEntry \<Tab>\<C-N>")
4912+
call VerifyScreenDump(buf, 'Test_long_line_noselect_2', {})
4913+
4914+
call term_sendkeys(buf, "\<Esc>:DoubleEntry \<Tab>\<C-N>\<C-N>")
4915+
call VerifyScreenDump(buf, 'Test_long_line_noselect_3', {})
4916+
" clean up
4917+
call term_sendkeys(buf, "\<Esc>")
4918+
call StopVimInTerminal(buf)
4919+
endfunc
4920+
48924921
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,8 @@ static char *(features[]) =
724724

725725
static int included_patches[] =
726726
{ /* Add new patch number below this line */
727+
/**/
728+
1676,
727729
/**/
728730
1675,
729731
/**/

src/vim.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
900900
#define WILD_NOERROR 0x800 // sets EW_NOERROR
901901
#define WILD_BUFLASTUSED 0x1000
902902
#define BUF_DIFF_FILTER 0x2000
903-
#define WILD_KEEP_SOLE_ITEM 0x4000
903+
#define WILD_NOSELECT 0x4000
904904
#define WILD_MAY_EXPAND_PATTERN 0x8000
905905
#define WILD_FUNC_TRIGGER 0x10000 // called from wildtrigger()
906906

0 commit comments

Comments
 (0)