Skip to content

Commit 017c269

Browse files
committed
patch 8.1.1676: "maxwidth" of popup window does not always work properly
Problem: "maxwidth" of popup window does not always work properly. Solution: Adjust the computation. (Naruhiko Nishino, closes #4653)
1 parent 7b73f91 commit 017c269

4 files changed

Lines changed: 64 additions & 0 deletions

File tree

src/popupwin.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,8 @@ popup_height(win_T *wp)
799799
int
800800
popup_width(win_T *wp)
801801
{
802+
// w_leftcol is how many columns of the core are left of the screen
803+
// w_popup_rightoff is how many columns of the core are right of the screen
802804
return wp->w_width + wp->w_leftcol
803805
+ wp->w_popup_padding[3] + wp->w_popup_border[3]
804806
+ wp->w_popup_padding[1] + wp->w_popup_border[1]
@@ -924,7 +926,11 @@ popup_adjust_position(win_T *wp)
924926
wp->w_width = maxwidth;
925927
}
926928
if (wp->w_width < len)
929+
{
927930
wp->w_width = len;
931+
if (wp->w_maxwidth > 0 && wp->w_width > wp->w_maxwidth)
932+
wp->w_width = wp->w_maxwidth;
933+
}
928934
// do not use the width of lines we're not going to show
929935
if (wp->w_maxheight > 0
930936
&& lnum - wp->w_topline + 1 + wrapped > wp->w_maxheight)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
>╔+0#0000001#ffd7ff255|═@2|╗| +0#0000000#ffffff0@9|╔+0#0000001#ffd7ff255|═@11|╗| +0#0000000#ffffff0@2|╔+0#0000001#ffd7ff255|═@12|╗| +0#0000000#ffffff0@27
2+
|║+0#0000001#ffd7ff255| @2|║| +0#0000000#ffffff0@9|║+0#0000001#ffd7ff255| @11|║| +0#0000000#ffffff0@2|║+0#0000001#ffd7ff255| @12|║| +0#0000000#ffffff0@27
3+
|║+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
4+
|║+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
5+
|╚+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+
|6| @30|║+0#0000001#ffd7ff255| @12|║| +0#0000000#ffffff0@27
7+
|╔+0#0000001#ffd7ff255|═@11|╗| +0#0000000#ffffff0|╔+0#0000001#ffd7ff255|═@11|╗| +0#0000000#ffffff0@2|╚+0#0000001#ffd7ff255|═@12|╝| +0#0000000#ffffff0@27
8+
|║+0#0000001#ffd7ff255| @11|║| +0#0000000#ffffff0|║+0#0000001#ffd7ff255| @11|║| +0#0000000#ffffff0@45
9+
|║+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
10+
|║+0#0000001#ffd7ff255| @11|║| +0#0000000#ffffff0|║+0#0000001#ffd7ff255| @11|║| +0#0000000#ffffff0@45
11+
|╚+0#0000001#ffd7ff255|═@11|╝| +0#4040ff13#ffffff0|╚+0#0000001#ffd7ff255|═@11|╝| +0#4040ff13#ffffff0@45
12+
|~| @73
13+
| +0#0000000&@56|1|,|1| @10|A|l@1|

src/testdir/test_popupwin.vim

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,3 +1819,46 @@ func Test_popupwin_buf_close()
18191819
call assert_equal([], bufinfo.popups)
18201820
exe 'bwipe! ' .. buf
18211821
endfunc
1822+
1823+
func Test_popup_menu_with_maxwidth()
1824+
if !CanRunVimInTerminal()
1825+
throw 'Skipped: cannot make screendumps'
1826+
endif
1827+
1828+
let lines =<< trim END
1829+
call setline(1, range(1, 10))
1830+
hi ScrollThumb ctermbg=blue
1831+
hi ScrollBar ctermbg=red
1832+
func PopupMenu(lines, line, col, scrollbar = 0)
1833+
return popup_menu(a:lines, {
1834+
\ 'maxwidth': 10,
1835+
\ 'maxheight': 3,
1836+
\ 'pos' : 'topleft',
1837+
\ 'col' : a:col,
1838+
\ 'line' : a:line,
1839+
\ 'scrollbar' : a:scrollbar,
1840+
\ })
1841+
endfunc
1842+
call PopupMenu(['x'], 1, 1)
1843+
call PopupMenu(['123456789|'], 1, 16)
1844+
call PopupMenu(['123456789|' .. ' '], 7, 1)
1845+
call PopupMenu([repeat('123456789|', 100)], 7, 16)
1846+
call PopupMenu(repeat(['123456789|' .. ' '], 5), 1, 33, 1)
1847+
END
1848+
call writefile(lines, 'XtestPopupMenuMaxWidth')
1849+
let buf = RunVimInTerminal('-S XtestPopupMenuMaxWidth', {'rows': 13})
1850+
call VerifyScreenDump(buf, 'Test_popupwin_menu_maxwidth_1', {})
1851+
1852+
" close the menu popupwin.
1853+
call term_sendkeys(buf, " ")
1854+
call term_sendkeys(buf, " ")
1855+
call term_sendkeys(buf, " ")
1856+
call term_sendkeys(buf, " ")
1857+
call term_sendkeys(buf, " ")
1858+
1859+
" clean up
1860+
call StopVimInTerminal(buf)
1861+
call delete('XtestPopupMenuMaxWidth')
1862+
endfunc
1863+
1864+
" 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+
1676,
780782
/**/
781783
1675,
782784
/**/

0 commit comments

Comments
 (0)