From: Hirohito Higashi Date: Thu, 30 Jul 2026 19:22:16 +0000 (+0000) Subject: patch 9.2.0879: popup: "maxwidth" is not respected when 'wrap' is off X-Git-Tag: v9.2.0879^0 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5ffc8c11d141bef8986529edebade6b272af6d9b;p=thirdparty%2Fvim.git patch 9.2.0879: popup: "maxwidth" is not respected when 'wrap' is off Problem: A popup window can become wider than "maxwidth" when 'wrap' is off and the popup is near the right edge of the screen. Solution: Do not shift the popup leftwards beyond "maxwidth", truncate the text instead, like it is done when 'wrap' is on. Reported: https://groups.google.com/g/vim_use/c/_rOLxGz5kNM/m/JFt7d81QCQAJ closes: #20883 Co-Authored-By: Claude Opus 5 (1M context) Signed-off-by: Hirohito Higashi Signed-off-by: Christian Brabandt --- diff --git a/src/popupwin.c b/src/popupwin.c index 2149ee0997..07e0b90e27 100644 --- a/src/popupwin.c +++ b/src/popupwin.c @@ -2665,10 +2665,9 @@ popup_adjust_position(win_T *wp) shift_by -= truncate_shift; } - // When wrapping is enabled and maxwidth is explicitly set, - // don't shift beyond maxwidth - let the text wrap instead. - if (wp->w_p_wrap && wp->w_maxwidth > 0 - && maxwidth + shift_by > wp->w_maxwidth) + // When maxwidth is explicitly set, don't shift beyond it, the text + // is wrapped or truncated instead. + if (wp->w_maxwidth > 0 && maxwidth + shift_by > wp->w_maxwidth) shift_by = wp->w_maxwidth - maxwidth; if (shift_by > 0) diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim index 701e33e52d..2663c52da2 100644 --- a/src/testdir/test_popupwin.vim +++ b/src/testdir/test_popupwin.vim @@ -2203,6 +2203,44 @@ func Test_popup_wrap_with_maxwidth() %bwipe! endfunc +func Test_popup_nowrap_with_maxwidth() + " When wrap is off and maxwidth is explicitly set, a popup near the right + " edge of the screen must not get wider than maxwidth by shifting left. + let maxw = 20 + let col = &columns - maxw + 1 + + " Text longer than maxwidth is truncated, no shift is needed. + let p = popup_create(repeat('x', 40), #{ + \ line: 5, col: col, maxwidth: maxw, wrap: 0}) + call s:VerifyPosition(p, 'nowrap with maxwidth at right edge', + \ 5, col, maxw, 1) + call popup_close(p) + + " Not enough space at the right: shift left, but only up to maxwidth. + let p = popup_create(repeat('y', 40), #{ + \ line: 5, col: &columns - 5, maxwidth: maxw, wrap: 0}) + call s:VerifyPosition(p, 'nowrap with maxwidth shifts up to maxwidth', + \ 5, col, maxw, 1) + call popup_close(p) + + " Same with a border and padding. + let p = popup_create(repeat('z', 40), #{ + \ line: 5, col: &columns - 5, maxwidth: maxw, wrap: 0, + \ border: [], padding: [0, 1, 0, 1]}) + call assert_equal(maxw, popup_getpos(p).core_width) + call popup_close(p) + + " When maxwidth is not set, shift-left uses the whole text width. + let p = popup_create(repeat('w', 40), #{ + \ line: 5, col: col, wrap: 0}) + call s:VerifyPosition(p, 'nowrap without maxwidth shifts left', + \ 5, col - maxw, 40, 1) + call popup_close(p) + + call popup_clear() + %bwipe! +endfunc + func Test_adjust_left_past_screen_width() " width of screen let X = join(map(range(&columns), {->'X'}), '') diff --git a/src/version.c b/src/version.c index 0e5c697ec9..5bc24b40a0 100644 --- a/src/version.c +++ b/src/version.c @@ -758,6 +758,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 879, /**/ 878, /**/