]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1521: completion: pum does not reset scroll pos on reopen with 'noselect' v9.1.1521
authorGirish Palya <girishji@gmail.com>
Mon, 7 Jul 2025 17:47:53 +0000 (19:47 +0200)
committerChristian Brabandt <cb@256bit.org>
Mon, 7 Jul 2025 17:47:53 +0000 (19:47 +0200)
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>
src/cmdexpand.c
src/testdir/dumps/Test_pum_scroll_noselect_1.dump [new file with mode: 0644]
src/testdir/dumps/Test_pum_scroll_noselect_2.dump [new file with mode: 0644]
src/testdir/test_cmdline.vim
src/version.c

index 13d540e77dc55241373880f6d7fe7a76efe33f19..d5730ab6b3c8dc6fe8cb3debb3c45386b84e63b2 100644 (file)
@@ -411,6 +411,7 @@ cmdline_pum_create(
     // 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 (file)
index 0000000..8e45c8a
--- /dev/null
@@ -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 (file)
index 0000000..24d8ca8
--- /dev/null
@@ -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
index c5a7d85c76e200c18028ec588dd362949ed47973..6aedf3ec29f4e713527514c915371a7a3a22feed 100644 (file)
@@ -4622,4 +4622,35 @@ func Test_range_complete()
   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
index a892dcb4a28c51371dd2bbaf872d1e7e70d2c4c6..e87aa4ecdbf876a80f9afa7e747483a511d19600 100644 (file)
@@ -719,6 +719,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1521,
 /**/
     1520,
 /**/