Skip to content

Commit a901a37

Browse files
committed
patch 8.1.1678: using popup_menu() does not scroll to show the selected line
Problem: When using popup_menu() does not scroll to show the selected line. Solution: Scroll the text. (Naruhiko Nishino, closes #4651)
1 parent b073da8 commit a901a37

9 files changed

Lines changed: 114 additions & 0 deletions

src/popupwin.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,12 @@ popup_highlight_curline(win_T *wp)
15121512

15131513
match_delete(wp, 1, FALSE);
15141514

1515+
// Scroll to show the line with the cursor. This assumes lines don't wrap.
1516+
while (wp->w_topline + wp->w_height - 1 < wp->w_cursor.lnum)
1517+
wp->w_topline++;
1518+
while (wp->w_cursor.lnum < wp->w_topline)
1519+
wp->w_topline--;
1520+
15151521
id = syn_name2id((char_u *)"PopupSelected");
15161522
vim_snprintf(buf, sizeof(buf), "\\%%%dl.*", (int)wp->w_cursor.lnum);
15171523
match_add(wp, (char_u *)(id == 0 ? "PmenuSel" : "PopupSelected"),
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
>1+0&#ffffff0| @73
2+
|2| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30
3+
|3| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30
4+
|4| @29|║+0#0000001#ffd7ff255| |o|n|e| @5| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
5+
|5| @29|║+0#0000001#ffd7ff255| |t+0&#e0e0e08|w|o| +0&#ffd7ff255@5| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
6+
|6| @29|║+0#0000001#ffd7ff255| |t|h|r|e@1| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
7+
|7| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30
8+
|8| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30
9+
|9| @73
10+
@57|1|,|1| @10|T|o|p|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
>1+0&#ffffff0| @73
2+
|2| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30
3+
|3| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30
4+
|4| @29|║+0#0000001#ffd7ff255| |t|h|r|e@1| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
5+
|5| @29|║+0#0000001#ffd7ff255| |f|o|u|r| @4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
6+
|6| @29|║+0#0000001#ffd7ff255| |f+0&#e0e0e08|i|v|e| +0&#ffd7ff255@4| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
7+
|7| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30
8+
|8| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30
9+
|9| @73
10+
@57|1|,|1| @10|T|o|p|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
>1+0&#ffffff0| @73
2+
|2| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30
3+
|3| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30
4+
|4| @29|║+0#0000001#ffd7ff255| |s|e|v|e|n| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
5+
|5| @29|║+0#0000001#ffd7ff255| |e|i|g|h|t| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
6+
|6| @29|║+0#0000001#ffd7ff255| |n+0&#e0e0e08|i|n|e| +0&#ffd7ff255@4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
7+
|7| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30
8+
|8| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30
9+
|9| @73
10+
@57|1|,|1| @10|T|o|p|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
>1+0&#ffffff0| @73
2+
|2| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30
3+
|3| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30
4+
|4| @29|║+0#0000001#ffd7ff255| |s+0&#e0e0e08|e|v|e|n| +0&#ffd7ff255@3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
5+
|5| @29|║+0#0000001#ffd7ff255| |e|i|g|h|t| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
6+
|6| @29|║+0#0000001#ffd7ff255| |n|i|n|e| @4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
7+
|7| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30
8+
|8| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30
9+
|9| @73
10+
@57|1|,|1| @10|T|o|p|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
>1+0&#ffffff0| @73
2+
|2| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30
3+
|3| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30
4+
|4| @29|║+0#0000001#ffd7ff255| |s+0&#e0e0e08|i|x| +0&#ffd7ff255@5| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
5+
|5| @29|║+0#0000001#ffd7ff255| |s|e|v|e|n| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
6+
|6| @29|║+0#0000001#ffd7ff255| |e|i|g|h|t| @3| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
7+
|7| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30
8+
|8| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30
9+
|9| @73
10+
@57|1|,|1| @10|T|o|p|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
>1+0&#ffffff0| @73
2+
|2| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30
3+
|3| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30
4+
|4| @29|║+0#0000001#ffd7ff255| |o+0&#e0e0e08|n|e| +0&#ffd7ff255@5| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
5+
|5| @29|║+0#0000001#ffd7ff255| |t|w|o| @5| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
6+
|6| @29|║+0#0000001#ffd7ff255| |t|h|r|e@1| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
7+
|7| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30
8+
|8| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30
9+
|9| @73
10+
@57|1|,|1| @10|T|o|p|

src/testdir/test_popupwin.vim

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,4 +1861,50 @@ func Test_popup_menu_with_maxwidth()
18611861
call delete('XtestPopupMenuMaxWidth')
18621862
endfunc
18631863

1864+
func Test_popup_menu_with_scrollbar()
1865+
if !CanRunVimInTerminal()
1866+
throw 'Skipped: cannot make screendumps'
1867+
endif
1868+
1869+
let lines =<< trim END
1870+
call setline(1, range(1, 20))
1871+
hi ScrollThumb ctermbg=blue
1872+
hi ScrollBar ctermbg=red
1873+
call popup_menu(['one', 'two', 'three', 'four', 'five',
1874+
\ 'six', 'seven', 'eight', 'nine'], {
1875+
\ 'minwidth': 8,
1876+
\ 'maxheight': 3,
1877+
\ })
1878+
END
1879+
call writefile(lines, 'XtestPopupMenuScroll')
1880+
let buf = RunVimInTerminal('-S XtestPopupMenuScroll', {'rows': 10})
1881+
1882+
call term_sendkeys(buf, "j")
1883+
call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_1', {})
1884+
1885+
call term_sendkeys(buf, "jjj")
1886+
call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_2', {})
1887+
1888+
" if the cursor is the bottom line, it stays at the bottom line.
1889+
call term_sendkeys(buf, repeat("j", 20))
1890+
call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_3', {})
1891+
1892+
call term_sendkeys(buf, "kk")
1893+
call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_4', {})
1894+
1895+
call term_sendkeys(buf, "k")
1896+
call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_5', {})
1897+
1898+
" if the cursor is in the top line, it stays in the top line.
1899+
call term_sendkeys(buf, repeat("k", 20))
1900+
call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_6', {})
1901+
1902+
" close the menu popupwin.
1903+
call term_sendkeys(buf, " ")
1904+
1905+
" clean up
1906+
call StopVimInTerminal(buf)
1907+
call delete('XtestPopupMenuScroll')
1908+
endfunc
1909+
18641910
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

778778
static int included_patches[] =
779779
{ /* Add new patch number below this line */
780+
/**/
781+
1678,
780782
/**/
781783
1677,
782784
/**/

0 commit comments

Comments
 (0)