patch 9.2.0247: popup: popups may not wrap as expected

Commit: 
https://github.com/vim/vim/commit/c0f0a34ea36120ad1cac3867a777f2c55ed88b09
Author: Hirohito Higashi <[email protected]>
Date:   Wed Mar 25 20:12:28 2026 +0000

    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) <[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 ed6f6fc1b..2188305de 100644
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -1516,8 +1516,17 @@ popup_adjust_position(win_T *wp)
                shift_by -= truncate_shift;
            }
 
-           wp->w_wincol -= shift_by;
-           maxwidth += shift_by;
+           // 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)
+               shift_by = wp->w_maxwidth - maxwidth;
+
+           if (shift_by > 0)
+           {
+               wp->w_wincol -= shift_by;
+               maxwidth += shift_by;
+           }
            wp->w_width = maxwidth;
        }
        if (wp->w_p_wrap)
diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim
index ab6a74d07..83610a486 100644
--- a/src/testdir/test_popupwin.vim
+++ b/src/testdir/test_popupwin.vim
@@ -2115,6 +2115,44 @@ func Test_popup_position_adjust()
   %bwipe!
 endfunc
 
+func Test_popup_wrap_with_maxwidth()
+  " When wrap is on and maxwidth is explicitly set, a popup near the right
+  " edge of the screen should wrap text within maxwidth, not shift left and
+  " display on one line.  Regression test for issue #19767.
+  let maxw = 20
+  let col = &columns - maxw + 1
+
+  " Text longer than maxwidth should wrap, not cause shift-left.
+  let p = popup_create(repeat('x', 40), #{
+       \ line: 5, col: col, maxwidth: maxw, pos: 'botleft'})
+  call s:VerifyPosition(p, 'wrap with maxwidth at right edge',
+       \ 4, col, maxw, 2)
+  call popup_close(p)
+
+  " Text much longer than maxwidth: should still wrap within maxwidth.
+  let p = popup_create(repeat('y', 80), #{
+       \ line: 10, col: col, maxwidth: maxw, pos: 'botleft'})
+  call s:VerifyPosition(p, 'wrap long text with maxwidth',
+       \ 7, col, maxw, 4)
+  call popup_close(p)
+
+  " Text shorter than maxwidth: no shift and no wrap needed.
+  let p = popup_create(repeat('z', 15), #{
+       \ line: 5, col: col, maxwidth: maxw, pos: 'botleft'})
+  call s:VerifyPosition(p, 'short text with maxwidth', 5, col, 15, 1)
+  call popup_close(p)
+
+  " When maxwidth is not set, shift-left should still work (patch 9.1.0949).
+  let p = popup_create(repeat('w', 40), #{
+       \ line: 5, col: col, pos: 'botleft'})
+  call s:VerifyPosition(p, 'wrap 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 b38010c07..c86fb7c32 100644
--- a/src/version.c
+++ b/src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    247,
 /**/
     246,
 /**/

-- 
-- 
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/E1w5Urc-005odg-9h%40256bit.org.

Raspunde prin e-mail lui