Mercurial > vim
changeset 17358:d1ea88736ebd v8.1.1678
patch 8.1.1678: using popup_menu() does not scroll to show the selected line
commit https://github.com/vim/vim/commit/a901a37bae9f4e2848d6d7ac7b0875d72f43e1eb
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jul 13 16:38:50 2019 +0200
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 https://github.com/vim/vim/issues/4651)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 13 Jul 2019 16:45:04 +0200 |
parents | 6ca0988117dd |
children | 2cdf1096554d |
files | src/popupwin.c src/testdir/dumps/Test_popupwin_menu_scroll_1.dump src/testdir/dumps/Test_popupwin_menu_scroll_2.dump src/testdir/dumps/Test_popupwin_menu_scroll_3.dump src/testdir/dumps/Test_popupwin_menu_scroll_4.dump src/testdir/dumps/Test_popupwin_menu_scroll_5.dump src/testdir/dumps/Test_popupwin_menu_scroll_6.dump src/testdir/test_popupwin.vim src/version.c |
diffstat | 9 files changed, 114 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/popupwin.c +++ b/src/popupwin.c @@ -1512,6 +1512,12 @@ popup_highlight_curline(win_T *wp) match_delete(wp, 1, FALSE); + // Scroll to show the line with the cursor. This assumes lines don't wrap. + while (wp->w_topline + wp->w_height - 1 < wp->w_cursor.lnum) + wp->w_topline++; + while (wp->w_cursor.lnum < wp->w_topline) + wp->w_topline--; + id = syn_name2id((char_u *)"PopupSelected"); vim_snprintf(buf, sizeof(buf), "\\%%%dl.*", (int)wp->w_cursor.lnum); match_add(wp, (char_u *)(id == 0 ? "PmenuSel" : "PopupSelected"),
new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_popupwin_menu_scroll_1.dump @@ -0,0 +1,10 @@ +>1+0&#ffffff0| @73 +|2| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30 +|3| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30 +|4| @29|║+0#0000001#ffd7ff255| |o|n|e| @5| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30 +|5| @29|║+0#0000001#ffd7ff255| |t+0&#e0e0e08|w|o| +0&#ffd7ff255@5| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30 +|6| @29|║+0#0000001#ffd7ff255| |t|h|r|e@1| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30 +|7| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30 +|8| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30 +|9| @73 +@57|1|,|1| @10|T|o|p|
new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_popupwin_menu_scroll_2.dump @@ -0,0 +1,10 @@ +>1+0&#ffffff0| @73 +|2| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30 +|3| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30 +|4| @29|║+0#0000001#ffd7ff255| |t|h|r|e@1| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30 +|5| @29|║+0#0000001#ffd7ff255| |f|o|u|r| @4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30 +|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| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30 +|8| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30 +|9| @73 +@57|1|,|1| @10|T|o|p|
new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_popupwin_menu_scroll_3.dump @@ -0,0 +1,10 @@ +>1+0&#ffffff0| @73 +|2| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30 +|3| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30 +|4| @29|║+0#0000001#ffd7ff255| |s|e|v|e|n| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30 +|5| @29|║+0#0000001#ffd7ff255| |e|i|g|h|t| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30 +|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| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30 +|8| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30 +|9| @73 +@57|1|,|1| @10|T|o|p|
new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_popupwin_menu_scroll_4.dump @@ -0,0 +1,10 @@ +>1+0&#ffffff0| @73 +|2| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30 +|3| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30 +|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| @29|║+0#0000001#ffd7ff255| |e|i|g|h|t| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30 +|6| @29|║+0#0000001#ffd7ff255| |n|i|n|e| @4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30 +|7| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30 +|8| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30 +|9| @73 +@57|1|,|1| @10|T|o|p|
new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_popupwin_menu_scroll_5.dump @@ -0,0 +1,10 @@ +>1+0&#ffffff0| @73 +|2| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30 +|3| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30 +|4| @29|║+0#0000001#ffd7ff255| |s+0&#e0e0e08|i|x| +0&#ffd7ff255@5| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30 +|5| @29|║+0#0000001#ffd7ff255| |s|e|v|e|n| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30 +|6| @29|║+0#0000001#ffd7ff255| |e|i|g|h|t| @3| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30 +|7| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30 +|8| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30 +|9| @73 +@57|1|,|1| @10|T|o|p|
new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_popupwin_menu_scroll_6.dump @@ -0,0 +1,10 @@ +>1+0&#ffffff0| @73 +|2| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30 +|3| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30 +|4| @29|║+0#0000001#ffd7ff255| |o+0&#e0e0e08|n|e| +0&#ffd7ff255@5| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30 +|5| @29|║+0#0000001#ffd7ff255| |t|w|o| @5| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30 +|6| @29|║+0#0000001#ffd7ff255| |t|h|r|e@1| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30 +|7| @29|║+0#0000001#ffd7ff255| @10|║| +0#0000000#ffffff0@30 +|8| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30 +|9| @73 +@57|1|,|1| @10|T|o|p|
--- a/src/testdir/test_popupwin.vim +++ b/src/testdir/test_popupwin.vim @@ -1861,4 +1861,50 @@ func Test_popup_menu_with_maxwidth() call delete('XtestPopupMenuMaxWidth') endfunc +func Test_popup_menu_with_scrollbar() + if !CanRunVimInTerminal() + throw 'Skipped: cannot make screendumps' + endif + + let lines =<< trim END + call setline(1, range(1, 20)) + hi ScrollThumb ctermbg=blue + hi ScrollBar ctermbg=red + call popup_menu(['one', 'two', 'three', 'four', 'five', + \ 'six', 'seven', 'eight', 'nine'], { + \ 'minwidth': 8, + \ 'maxheight': 3, + \ }) + END + call writefile(lines, 'XtestPopupMenuScroll') + let buf = RunVimInTerminal('-S XtestPopupMenuScroll', {'rows': 10}) + + call term_sendkeys(buf, "j") + call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_1', {}) + + call term_sendkeys(buf, "jjj") + call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_2', {}) + + " if the cursor is the bottom line, it stays at the bottom line. + call term_sendkeys(buf, repeat("j", 20)) + call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_3', {}) + + call term_sendkeys(buf, "kk") + call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_4', {}) + + call term_sendkeys(buf, "k") + call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_5', {}) + + " if the cursor is in the top line, it stays in the top line. + call term_sendkeys(buf, repeat("k", 20)) + call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_6', {}) + + " close the menu popupwin. + call term_sendkeys(buf, " ") + + " clean up + call StopVimInTerminal(buf) + call delete('XtestPopupMenuScroll') +endfunc + " vim: shiftwidth=2 sts=2 expandtab