Skip to content

Commit 18f24b8

Browse files
committed
vim-patch:9.1.1740: Memory leak with wildmode=longest,full and wildoptions=pum
Problem: Memory leak with wildmode=longest,full and wildoptions=pum (after 9.1.1737). Solution: Avoid using showmatches() and WILD_NEXT together. Also fix wildmode=longest,noselect:full selecting wrong item (zeertzjq). fixes: vim/vim#18228 closes: vim/vim#18229 vim/vim@c7f235b
1 parent d784ed7 commit 18f24b8

File tree

3 files changed

+53
-9
lines changed

3 files changed

+53
-9
lines changed

src/nvim/ex_getln.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,13 +1188,11 @@ static int command_line_wildchar_complete(CommandLineState *s)
11881188
bool wim_full_next = (wim_flags[1] & kOptWimFlagFull);
11891189
bool wim_noselect_next = (wim_flags[1] & kOptWimFlagNoselect);
11901190
if (wim_list_next || (p_wmnu && (wim_full_next || wim_noselect_next))) {
1191-
if (wim_noselect_next) {
1192-
options |= WILD_NOSELECT;
1193-
}
1194-
if (wim_full_next || wim_noselect_next) {
1191+
if (wim_full_next && !wim_noselect_next) {
11951192
nextwild(&s->xpc, WILD_NEXT, options, escape);
1193+
} else {
1194+
showmatches(&s->xpc, p_wmnu, wim_list_next, wim_noselect_next);
11961195
}
1197-
showmatches(&s->xpc, p_wmnu, wim_list_next, wim_noselect_next);
11981196
if (wim_list_next) {
11991197
s->did_wild_list = true;
12001198
}

test/functional/ui/popupmenu_spec.lua

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4795,9 +4795,10 @@ describe('builtin popupmenu', function()
47954795
:cn^ |
47964796
]])
47974797

4798-
feed('<C-U><Esc>')
47994798
command('set wildmode& wildoptions=pum')
48004799

4800+
feed('<C-U><Esc>')
4801+
48014802
-- check positioning with multibyte char in pattern
48024803
command('e långfile1')
48034804
command('sp långfile2')
@@ -4981,24 +4982,52 @@ describe('builtin popupmenu', function()
49814982

49824983
-- pressing <Tab> should display the wildmenu
49834984
feed('<Tab>')
4984-
screen:expect([[
4985+
local s1 = [[
49854986
|
49864987
{1:~ }|*4
49874988
{1:~ }{12: undefine }{1: }|
49884989
{1:~ }{n: unplace }{1: }|
49894990
:sign undefine^ |
4990-
]])
4991+
]]
4992+
screen:expect(s1)
49914993
eq(1, fn.wildmenumode())
49924994

49934995
-- pressing <Tab> second time should select the next entry in the menu
49944996
feed('<Tab>')
4995-
screen:expect([[
4997+
local s2 = [[
49964998
|
49974999
{1:~ }|*4
49985000
{1:~ }{n: undefine }{1: }|
49995001
{1:~ }{12: unplace }{1: }|
50005002
:sign unplace^ |
5003+
]]
5004+
screen:expect(s2)
5005+
eq(1, fn.wildmenumode())
5006+
5007+
-- If "longest" finds no candidate in "longest,full", "full" is used
5008+
feed('<Esc>')
5009+
command('set wildmode=longest,full')
5010+
command('set wildoptions=pum')
5011+
feed(':sign un<Tab>')
5012+
screen:expect(s1)
5013+
feed('<Tab>')
5014+
screen:expect(s2)
5015+
5016+
-- Similarly for "longest,noselect:full"
5017+
feed('<Esc>')
5018+
command('set wildmode=longest,noselect:full')
5019+
feed(':sign un<Tab>')
5020+
screen:expect([[
5021+
|
5022+
{1:~ }|*4
5023+
{1:~ }{n: undefine }{1: }|
5024+
{1:~ }{n: unplace }{1: }|
5025+
:sign un^ |
50015026
]])
5027+
feed('<Tab>')
5028+
screen:expect(s1)
5029+
feed('<Tab>')
5030+
screen:expect(s2)
50025031
end)
50035032

50045033
it('wildoptions=pum with a wrapped line in buffer vim-patch:8.2.4655', function()

test/old/testdir/test_cmdline.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3044,6 +3044,23 @@ func Test_wildmenu_pum()
30443044
call term_sendkeys(buf, ":cn\<Tab>")
30453045
call VerifyScreenDump(buf, 'Test_wildmenu_pum_64', {})
30463046

3047+
" If "longest" finds no candidate in "longest,full", "full" is used
3048+
call term_sendkeys(buf, "\<Esc>:set wildmode=longest,full\<CR>")
3049+
call term_sendkeys(buf, ":set wildoptions=pum\<CR>")
3050+
call term_sendkeys(buf, ":sign un\<Tab>")
3051+
call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
3052+
call term_sendkeys(buf, "\<Tab>")
3053+
call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
3054+
3055+
" Similarly for "longest,noselect:full"
3056+
call term_sendkeys(buf, "\<Esc>:set wildmode=longest,noselect:full\<CR>")
3057+
call term_sendkeys(buf, ":sign un\<Tab>")
3058+
call VerifyScreenDump(buf, 'Test_wildmenu_pum_65', {})
3059+
call term_sendkeys(buf, "\<Tab>")
3060+
call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
3061+
call term_sendkeys(buf, "\<Tab>")
3062+
call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
3063+
30473064
call term_sendkeys(buf, "\<C-U>\<Esc>")
30483065
call StopVimInTerminal(buf)
30493066
endfunc

0 commit comments

Comments
 (0)