patch 9.1.1521: completion: pum does not reset scroll pos on reopen with 'noselect'
Problem: When 'wildmode' is set to include "noselect", the popup menu (pum)
incorrectly retained its scroll position when reopened. This
meant that after scrolling down through the menu with `<C-n>`,
reopening the menu (e.g., by retyping the command and
triggering completion again) would show the menu starting from
the previously scrolled position, rather than from the top.
This could confuse users, as the first visible item would not
be the first actual match in the list.
Solution: Ensure that the popup menu resets its scroll position to the
top when reopened (Girish Palya).
closes: #17673
Signed-off-by: Girish Palya <girishji@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/cmdexpand.c b/src/cmdexpand.c
index 13d540e..d5730ab 100644
--- a/src/cmdexpand.c
+++ b/src/cmdexpand.c
@@ -411,6 +411,7 @@
// no default selection
compl_selected = -1;
+ pum_clear();
cmdline_pum_display();
return EXPAND_OK;
diff --git a/src/testdir/dumps/Test_pum_scroll_noselect_1.dump b/src/testdir/dumps/Test_pum_scroll_noselect_1.dump
new file mode 100644
index 0000000..8e45c8a
--- /dev/null
+++ b/src/testdir/dumps/Test_pum_scroll_noselect_1.dump
@@ -0,0 +1,10 @@
+| +0&#ffffff0@7| +0#0000001#ffd7ff255|a|1|5| @11| +0#0000000#a8a8a8255| +0&#ffffff0@49
+|~+0#4040ff13&| @6| +0#0000001#ffd7ff255|a|1|6| @11| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@49
+|~| @6| +0#0000001#ffd7ff255|a|1|7| @11| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@49
+|~| @6| +0#0000001#ffd7ff255|a|1|8| @11| +0#0000000#0000001| +0#4040ff13#ffffff0@49
+|~| @6| +0#0000001#ffd7ff255|a|1|9| @11| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@49
+|~| @6| +0#0000001#e0e0e08|a|2|0| @11| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@49
+|~| @6| +0#0000001#ffd7ff255|a|2|1| @11| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@49
+|~| @6| +0#0000001#ffd7ff255|a|2@1| @11| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@49
+|~| @6| +0#0000001#ffd7ff255|a|2|3| @11| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@49
+|:+0#0000000&|T|e|s|t|C|m|d| |a|2|0> @62
diff --git a/src/testdir/dumps/Test_pum_scroll_noselect_2.dump b/src/testdir/dumps/Test_pum_scroll_noselect_2.dump
new file mode 100644
index 0000000..24d8ca8
--- /dev/null
+++ b/src/testdir/dumps/Test_pum_scroll_noselect_2.dump
@@ -0,0 +1,10 @@
+| +0&#ffffff0@7| +0#0000001#ffd7ff255|a|1| @12| +0#0000000#0000001| +0&#ffffff0@49
+|~+0#4040ff13&| @6| +0#0000001#ffd7ff255|a|2| @12| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@49
+|~| @6| +0#0000001#ffd7ff255|a|3| @12| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@49
+|~| @6| +0#0000001#ffd7ff255|a|4| @12| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@49
+|~| @6| +0#0000001#ffd7ff255|a|5| @12| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@49
+|~| @6| +0#0000001#ffd7ff255|a|6| @12| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@49
+|~| @6| +0#0000001#ffd7ff255|a|7| @12| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@49
+|~| @6| +0#0000001#ffd7ff255|a|8| @12| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@49
+|~| @6| +0#0000001#ffd7ff255|a|9| @12| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@49
+|:+0#0000000&|T|e|s|t|C|m|d| > @65
diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim
index c5a7d85..6aedf3e 100644
--- a/src/testdir/test_cmdline.vim
+++ b/src/testdir/test_cmdline.vim
@@ -4622,4 +4622,35 @@
set wildcharm=0
endfunc
+" With 'noselect' in 'wildmode', ensure that the popup menu (pum) does not retain
+" its scroll position after reopening. The menu should open showing the top items,
+" regardless of previous scrolling.
+func Test_pum_scroll_noselect()
+ CheckScreendump
+
+ let lines =<< trim [SCRIPT]
+ command! -nargs=* -complete=customlist,TestFn TestCmd echo
+ func TestFn(a, b, c)
+ return map(range(1, 50), 'printf("a%d", v:val)')
+ endfunc
+ set wildmode=noselect,full
+ set wildoptions=pum
+ set wildmenu
+ set noruler
+ [SCRIPT]
+ call writefile(lines, 'XTest_pum_scroll', 'D')
+ let buf = RunVimInTerminal('-S XTest_pum_scroll', {'rows': 10})
+
+ call term_sendkeys(buf, ":TestCmd \<tab>" . repeat("\<c-n>", 20))
+ call TermWait(buf, 50)
+ call VerifyScreenDump(buf, 'Test_pum_scroll_noselect_1', {})
+
+ call term_sendkeys(buf, "\<esc>:TestCmd \<tab>")
+ call TermWait(buf, 50)
+ call VerifyScreenDump(buf, 'Test_pum_scroll_noselect_2', {})
+
+ call term_sendkeys(buf, "\<esc>")
+ call StopVimInTerminal(buf)
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index a892dcb..e87aa4e 100644
--- a/src/version.c
+++ b/src/version.c
@@ -720,6 +720,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1521,
+/**/
1520,
/**/
1519,