Commit: patch 9.2.0879: popup: "maxwidth" is not respected when 'wrap' is off

Christian Brabandt <[email protected]> Thu, 30 Jul 2026 21:30:04 +0200
Newsgroups gmane.editors.vim.devel
Message-ID <[email protected]>
patch 9.2.0879: popup: "maxwidth" is not respected when 'wrap' is off

Commit: https://github.com/vim/vim/commit/5ffc8c11d141bef8986529edebade6b272af6d9b
Author: Hirohito Higashi <[email protected]>
Date:   Thu Jul 30 19:22:16 2026 +0000

    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) <[email protected]>
    Signed-off-by: Hirohito Higashi <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/popupwin.c b/src/popupwin.c
index 2149ee099..07e0b90e2 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 701e33e52..2663c52da 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 0e5c697ec..5bc24b40a 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,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1wpWSC-004bs3-Vk%40256bit.org.