]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0879: popup: "maxwidth" is not respected when 'wrap' is off v9.2.0879
authorHirohito Higashi <h.east.727@gmail.com>
Thu, 30 Jul 2026 19:22:16 +0000 (19:22 +0000)
committerChristian Brabandt <cb@256bit.org>
Thu, 30 Jul 2026 19:22:16 +0000 (19:22 +0000)
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) <noreply@anthropic.com>
Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/popupwin.c
src/testdir/test_popupwin.vim
src/version.c

index 2149ee0997a990cf2632a92839f33fd28da56404..07e0b90e27e0ccd246328e78459dab6d4439d7dc 100644 (file)
@@ -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)
index 701e33e52d6256b0f2924c5836edf7c4e185b2f6..2663c52da2715cdc99ff5b001aab3200517629f0 100644 (file)
@@ -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'}), '')
index 0e5c697ec9180ae8dc1da6c62203d41b2396b791..5bc24b40a030f23ee040fe4a8f6c3a278611533e 100644 (file)
@@ -758,6 +758,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    879,
 /**/
     878,
 /**/