patch 8.1.1945: popup window "firstline" cannot be reset
Problem: Popup window "firstline" cannot be reset.
Solution: Allow for setting "firstline" to zero. Fix that the text jumps to
the top when using win_execute(). (closes #4876)
diff --git a/src/popupwin.c b/src/popupwin.c
index dfc0c89..8d4a9f2 100644
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -610,8 +610,8 @@
di = dict_find(dict, (char_u *)"firstline", -1);
if (di != NULL)
wp->w_firstline = dict_get_number(dict, (char_u *)"firstline");
- if (wp->w_firstline < 1)
- wp->w_firstline = 1;
+ if (wp->w_firstline < 0)
+ wp->w_firstline = 0;
di = dict_find(dict, (char_u *)"scrollbar", -1);
if (di != NULL)
@@ -3192,8 +3192,17 @@
// Draw the popup text, unless it's off screen.
if (wp->w_winrow < screen_Rows && wp->w_wincol < screen_Columns)
+ {
win_update(wp);
+ // move the cursor into the visible lines, otherwise executing
+ // commands with win_execute() may cause the text to jump.
+ if (wp->w_cursor.lnum < wp->w_topline)
+ wp->w_cursor.lnum = wp->w_topline;
+ else if (wp->w_cursor.lnum >= wp->w_botline)
+ wp->w_cursor.lnum = wp->w_botline - 1;
+ }
+
wp->w_winrow -= top_off;
wp->w_wincol -= left_extra;