[vim/vim] popup: "maxwidth" is not respected when 'wrap' is off (PR #20883)

h_east (Vim Github Repository) <[email protected]> Thu, 30 Jul 2026 07:00:42 -0700
Newsgroups gmane.editors.vim.devel
Message-ID <vim/vim/pull/[email protected]>
```
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 on vim_use:
https://groups.google.com/g/vim_use/c/_rOLxGz5kNM/m/JFt7d81QCQAJ

---

When 'wrap' is off and the popup is near the right edge of the screen, the
popup is made as wide as the longest text line and "maxwidth" has no effect.
With a 120 column screen:

    call popup_create([repeat('x', 93)],
                \ #{line: 3, col: 80, maxwidth: 50, wrap: 0, border: []})

Before this change the popup is drawn 93 cells wide and popup_getpos()
reports core_width 93 instead of 50.  The same happens with popup_atcursor()
when the cursor is near the right edge, with a popup anchored to a text
property, and after moving a popup to the right with popup_move().

The popup is shifted leftwards to make the text fit on the screen.  This
shift is skipped only when "maxwidth" is smaller than the space left of the
right edge, so close to the right edge the shift raises the width limit
itself.  Patch 9.2.0247 added a check against this, but only for 'wrap'
being on.

The overflow is not new, but since patch 9.2.0419 reserves room for the
right border and padding in the available space, the range of positions
where it shows up got wider by that amount.

No documentation change is needed, popup.txt already describes "maxwidth"
as the maximum width of the contents.
You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/20883

-- Commit Summary --

  * popup: "maxwidth" is not respected when 'wrap' is off

-- File Changes --

    M src/popupwin.c (7)
    M src/testdir/test_popupwin.vim (38)

-- Patch Links --

https://github.com/vim/vim/pull/20883.patch
https://github.com/vim/vim/pull/20883.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/vim/vim/pull/20883
You are receiving this because you are subscribed to this thread.

Message ID: <vim/vim/pull/[email protected]>

-- 
-- 
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/vim/vim/pull/20883%40github.com.