Skip to content

Commit c0f0a34

Browse files
h-eastclaude
authored andcommitted
patch 9.2.0247: popup: popups may not wrap as expected
Problem: popup: popups may not wrap as expected (Enrico Maria De Angelis, after v9.1.0949) Solution: don't shift popupwin left when 'wrap' is on and maxwidth is set (Hirohito Higashi) When a non-fixed popup with 'wrap' enabled and an explicit maxwidth was placed near the right edge of the screen, the shift-left logic increased maxwidth beyond the user-specified value, preventing text from wrapping. Instead cap the shift amount so that maxwidth does not exceed w_maxwidth when wrapping is enabled, letting text wrap as expected. fixes: #19767 closes: #19809 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Hirohito Higashi <h.east.727@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 4184000 commit c0f0a34

3 files changed

Lines changed: 51 additions & 2 deletions

File tree

src/popupwin.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,8 +1516,17 @@ popup_adjust_position(win_T *wp)
15161516
shift_by -= truncate_shift;
15171517
}
15181518

1519-
wp->w_wincol -= shift_by;
1520-
maxwidth += shift_by;
1519+
// When wrapping is enabled and maxwidth is explicitly set,
1520+
// don't shift beyond maxwidth - let the text wrap instead.
1521+
if (wp->w_p_wrap && wp->w_maxwidth > 0
1522+
&& maxwidth + shift_by > wp->w_maxwidth)
1523+
shift_by = wp->w_maxwidth - maxwidth;
1524+
1525+
if (shift_by > 0)
1526+
{
1527+
wp->w_wincol -= shift_by;
1528+
maxwidth += shift_by;
1529+
}
15211530
wp->w_width = maxwidth;
15221531
}
15231532
if (wp->w_p_wrap)

src/testdir/test_popupwin.vim

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,6 +2115,44 @@ func Test_popup_position_adjust()
21152115
%bwipe!
21162116
endfunc
21172117

2118+
func Test_popup_wrap_with_maxwidth()
2119+
" When wrap is on and maxwidth is explicitly set, a popup near the right
2120+
" edge of the screen should wrap text within maxwidth, not shift left and
2121+
" display on one line. Regression test for issue #19767.
2122+
let maxw = 20
2123+
let col = &columns - maxw + 1
2124+
2125+
" Text longer than maxwidth should wrap, not cause shift-left.
2126+
let p = popup_create(repeat('x', 40), #{
2127+
\ line: 5, col: col, maxwidth: maxw, pos: 'botleft'})
2128+
call s:VerifyPosition(p, 'wrap with maxwidth at right edge',
2129+
\ 4, col, maxw, 2)
2130+
call popup_close(p)
2131+
2132+
" Text much longer than maxwidth: should still wrap within maxwidth.
2133+
let p = popup_create(repeat('y', 80), #{
2134+
\ line: 10, col: col, maxwidth: maxw, pos: 'botleft'})
2135+
call s:VerifyPosition(p, 'wrap long text with maxwidth',
2136+
\ 7, col, maxw, 4)
2137+
call popup_close(p)
2138+
2139+
" Text shorter than maxwidth: no shift and no wrap needed.
2140+
let p = popup_create(repeat('z', 15), #{
2141+
\ line: 5, col: col, maxwidth: maxw, pos: 'botleft'})
2142+
call s:VerifyPosition(p, 'short text with maxwidth', 5, col, 15, 1)
2143+
call popup_close(p)
2144+
2145+
" When maxwidth is not set, shift-left should still work (patch 9.1.0949).
2146+
let p = popup_create(repeat('w', 40), #{
2147+
\ line: 5, col: col, pos: 'botleft'})
2148+
call s:VerifyPosition(p, 'wrap without maxwidth shifts left',
2149+
\ 5, col - maxw, 40, 1)
2150+
call popup_close(p)
2151+
2152+
call popup_clear()
2153+
%bwipe!
2154+
endfunc
2155+
21182156
func Test_adjust_left_past_screen_width()
21192157
" width of screen
21202158
let X = join(map(range(&columns), {->'X'}), '')

src/version.c

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

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
247,
737739
/**/
738740
246,
739741
/**/

0 commit comments

Comments
 (0)