diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-07-13 14:17:51 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-07-13 14:17:51 +0200 |
commit | 017c2699381be17131a02f051ecb812067289856 (patch) | |
tree | 67e71f499c17aeab4ff6b476668ebab0099f65f8 /src | |
parent | 7b73f914c4fc5a3f7ad97b678cc8137f964e3d62 (diff) | |
download | vim-git-017c2699381be17131a02f051ecb812067289856.tar.gz |
patch 8.1.1676: "maxwidth" of popup window does not always work properlyv8.1.1676
Problem: "maxwidth" of popup window does not always work properly.
Solution: Adjust the computation. (Naruhiko Nishino, closes #4653)
Diffstat (limited to 'src')
-rw-r--r-- | src/popupwin.c | 6 | ||||
-rw-r--r-- | src/testdir/dumps/Test_popupwin_menu_maxwidth_1.dump | 13 | ||||
-rw-r--r-- | src/testdir/test_popupwin.vim | 43 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 64 insertions, 0 deletions
diff --git a/src/popupwin.c b/src/popupwin.c index ea85588f2..3185686de 100644 --- a/src/popupwin.c +++ b/src/popupwin.c @@ -799,6 +799,8 @@ popup_height(win_T *wp) int popup_width(win_T *wp) { + // w_leftcol is how many columns of the core are left of the screen + // w_popup_rightoff is how many columns of the core are right of the screen return wp->w_width + wp->w_leftcol + wp->w_popup_padding[3] + wp->w_popup_border[3] + wp->w_popup_padding[1] + wp->w_popup_border[1] @@ -924,7 +926,11 @@ popup_adjust_position(win_T *wp) wp->w_width = maxwidth; } if (wp->w_width < len) + { wp->w_width = len; + if (wp->w_maxwidth > 0 && wp->w_width > wp->w_maxwidth) + wp->w_width = wp->w_maxwidth; + } // do not use the width of lines we're not going to show if (wp->w_maxheight > 0 && lnum - wp->w_topline + 1 + wrapped > wp->w_maxheight) diff --git a/src/testdir/dumps/Test_popupwin_menu_maxwidth_1.dump b/src/testdir/dumps/Test_popupwin_menu_maxwidth_1.dump new file mode 100644 index 000000000..171116537 --- /dev/null +++ b/src/testdir/dumps/Test_popupwin_menu_maxwidth_1.dump @@ -0,0 +1,13 @@ +>╔+0#0000001#ffd7ff255|═@2|╗| +0#0000000#ffffff0@9|╔+0#0000001#ffd7ff255|═@11|╗| +0#0000000#ffffff0@2|╔+0#0000001#ffd7ff255|═@12|╗| +0#0000000#ffffff0@27 +|║+0#0000001#ffd7ff255| @2|║| +0#0000000#ffffff0@9|║+0#0000001#ffd7ff255| @11|║| +0#0000000#ffffff0@2|║+0#0000001#ffd7ff255| @12|║| +0#0000000#ffffff0@27 +|║+0#0000001#ffd7ff255| |x+0&#e0e0e08| +0&#ffd7ff255|║| +0#0000000#ffffff0@9|║+0#0000001#ffd7ff255| |1+0&#e0e0e08|2|3|4|5|6|7|8|9||| +0&#ffd7ff255|║| +0#0000000#ffffff0@2|║+0#0000001#ffd7ff255| |1+0&#e0e0e08|2|3|4|5|6|7|8|9||| +0&#ffd7ff255| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@27 +|║+0#0000001#ffd7ff255| @2|║| +0#0000000#ffffff0@9|║+0#0000001#ffd7ff255| @11|║| +0#0000000#ffffff0@2|║+0#0000001#ffd7ff255| |1|2|3|4|5|6|7|8|9||| | +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@27 +|╚+0#0000001#ffd7ff255|═@2|╝| +0#0000000#ffffff0@9|╚+0#0000001#ffd7ff255|═@11|╝| +0#0000000#ffffff0@2|║+0#0000001#ffd7ff255| |1|2|3|4|5|6|7|8|9||| | +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@27 +|6| @30|║+0#0000001#ffd7ff255| @12|║| +0#0000000#ffffff0@27 +|╔+0#0000001#ffd7ff255|═@11|╗| +0#0000000#ffffff0|╔+0#0000001#ffd7ff255|═@11|╗| +0#0000000#ffffff0@2|╚+0#0000001#ffd7ff255|═@12|╝| +0#0000000#ffffff0@27 +|║+0#0000001#ffd7ff255| @11|║| +0#0000000#ffffff0|║+0#0000001#ffd7ff255| @11|║| +0#0000000#ffffff0@45 +|║+0#0000001#ffd7ff255| |1+0&#e0e0e08|2|3|4|5|6|7|8|9||| +0&#ffd7ff255|║| +0#0000000#ffffff0|║+0#0000001#ffd7ff255| |1+0&#e0e0e08|2|3|4|5|6|7|8|9||| +0&#ffd7ff255|║| +0#0000000#ffffff0@45 +|║+0#0000001#ffd7ff255| @11|║| +0#0000000#ffffff0|║+0#0000001#ffd7ff255| @11|║| +0#0000000#ffffff0@45 +|╚+0#0000001#ffd7ff255|═@11|╝| +0#4040ff13#ffffff0|╚+0#0000001#ffd7ff255|═@11|╝| +0#4040ff13#ffffff0@45 +|~| @73 +| +0#0000000&@56|1|,|1| @10|A|l@1| diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim index a55e913a9..456e0db1e 100644 --- a/src/testdir/test_popupwin.vim +++ b/src/testdir/test_popupwin.vim @@ -1819,3 +1819,46 @@ func Test_popupwin_buf_close() call assert_equal([], bufinfo.popups) exe 'bwipe! ' .. buf endfunc + +func Test_popup_menu_with_maxwidth() + if !CanRunVimInTerminal() + throw 'Skipped: cannot make screendumps' + endif + + let lines =<< trim END + call setline(1, range(1, 10)) + hi ScrollThumb ctermbg=blue + hi ScrollBar ctermbg=red + func PopupMenu(lines, line, col, scrollbar = 0) + return popup_menu(a:lines, { + \ 'maxwidth': 10, + \ 'maxheight': 3, + \ 'pos' : 'topleft', + \ 'col' : a:col, + \ 'line' : a:line, + \ 'scrollbar' : a:scrollbar, + \ }) + endfunc + call PopupMenu(['x'], 1, 1) + call PopupMenu(['123456789|'], 1, 16) + call PopupMenu(['123456789|' .. ' '], 7, 1) + call PopupMenu([repeat('123456789|', 100)], 7, 16) + call PopupMenu(repeat(['123456789|' .. ' '], 5), 1, 33, 1) + END + call writefile(lines, 'XtestPopupMenuMaxWidth') + let buf = RunVimInTerminal('-S XtestPopupMenuMaxWidth', {'rows': 13}) + call VerifyScreenDump(buf, 'Test_popupwin_menu_maxwidth_1', {}) + + " close the menu popupwin. + call term_sendkeys(buf, " ") + call term_sendkeys(buf, " ") + call term_sendkeys(buf, " ") + call term_sendkeys(buf, " ") + call term_sendkeys(buf, " ") + + " clean up + call StopVimInTerminal(buf) + call delete('XtestPopupMenuMaxWidth') +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c index 7e3c18059..c4fee1c0f 100644 --- a/src/version.c +++ b/src/version.c @@ -778,6 +778,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1676, +/**/ 1675, /**/ 1674, |