patch 9.1.1650: popup: window may not properly resize
Commit:
https://github.com/vim/vim/commit/31170af24a107d7f145a679ea624b0bba4b98d9b
Author: glepnir <[email protected]>
Date: Mon Aug 18 21:14:48 2025 +0200
patch 9.1.1650: popup: window may not properly resize
Problem: After scrolling a popup and then using popup_settext() with
fewer lines, the popup fails to resize properly because
firstline points beyond the new buffer content (lifepillar)
Solution: In popup_adjust_position(), validate that firstline doesn't
exceed buffer line count and reset to 0 (auto-position) if it
does (glepnir)
fixes: #14745
closes: #18031
Signed-off-by: glepnir <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/src/popupwin.c b/src/popupwin.c
index 7b1237c5f..2f956a3ad 100644
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -1403,7 +1403,15 @@ popup_adjust_position(win_T *wp)
// start at the desired first line
if (wp->w_firstline > 0)
- wp->w_topline = wp->w_firstline;
+ {
+ // If firstline is beyond the buffer content, reset it to auto-position.
+ // This can happen when the popup was scrolled and then the buffer
+ // content was changed to have fewer lines.
+ if (wp->w_firstline > wp->w_buffer->b_ml.ml_line_count)
+ wp->w_firstline = 0;
+ else
+ wp->w_topline = wp->w_firstline;
+ }
if (wp->w_topline < 1)
wp->w_topline = 1;
else if (wp->w_topline > wp->w_buffer->b_ml.ml_line_count)
diff --git a/src/testdir/dumps/Test_popupwin_first_after_scroll.dump
b/src/testdir/dumps/Test_popupwin_first_after_scroll.dump
new file mode 100644
index 000000000..74591df79
--- /dev/null
+++ b/src/testdir/dumps/Test_popupwin_first_after_scroll.dump
@@ -0,0 +1,20 @@
+> +0&#ffffff0@74
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~|╔+0#0000001#ffd7ff255|═@69|╗| +0#4040ff13#ffffff0@1
+|~|║+0#0000001#ffd7ff255|a| @68|║| +0#4040ff13#ffffff0@1
+|~|║+0#0000001#ffd7ff255|b| @68|║| +0#4040ff13#ffffff0@1
+|~|║+0#0000001#ffd7ff255|c| @68|║| +0#4040ff13#ffffff0@1
+|~|╚+0#0000001#ffd7ff255|═@69|╝| +0#4040ff13#ffffff0@1
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|:+0#0000000&|c|a|l@1| |p|o|p|u|p|_|s|e|t@1|e|x|t|(|1|0@1|1|,| |[|'|a|'|,|
|'|b|'|,| |'|c|'|]|)| @14|0|,|0|-|1| @8|A|l@1|
diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim
index ab99e5d7c..ed903bdbb 100644
--- a/src/testdir/test_popupwin.vim
+++ b/src/testdir/test_popupwin.vim
@@ -4533,4 +4533,41 @@ func Test_popupwin_closing_buffer()
%bd!
endfunc
+func Test_popupwin_firstline_after_scroll()
+ CheckScreendump
+
+ let lines =<< trim END
+ vim9script
+
+ def Popup(): number
+ return popup_create([], {
+ border: [1, 1, 1, 1],
+ close: 'click',
+ minheight: 1,
+ maxheight: 10,
+ scrollbar: true,
+ minwidth: &columns - 5,
+ maxwidth: &columns - 5,
+ })
+ enddef
+
+ var id = Popup()
+ g:popup_id = id
+ popup_settext(id, repeat(['abcd'], 20))
+ END
+ call writefile(lines, 'XtestPopupScroll_win', 'D')
+ let buf = RunVimInTerminal('-S XtestPopupScroll_win', {})
+ call TermWait(buf, 50)
+
+ call term_sendkeys(buf, ":call popup_setoptions(g:popup_id, {'firstline':
6})\<CR>")
+ call TermWait(buf, 50)
+ call term_sendkeys(buf, ":call popup_settext(g:popup_id, [])\<CR>")
+ call TermWait(buf, 50)
+ call term_sendkeys(buf, ":call popup_settext(1001, ['a', 'b', 'c'])\<CR>")
+ call TermWait(buf, 50)
+ call VerifyScreenDump(buf, 'Test_popupwin_first_after_scroll', {})
+
+ call StopVimInTerminal(buf)
+endfunc
+
" vim: shiftwidth=2 sts=2
diff --git a/src/version.c b/src/version.c
index 8f351ed07..a50755f53 100644
--- a/src/version.c
+++ b/src/version.c
@@ -719,6 +719,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1650,
/**/
1649,
/**/
--
--
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/E1uo5YS-005PWO-Cr%40256bit.org.