Patch 8.1.2009
Problem: Cursorline highlighting not updated in popup window. (Marko
Mahnič)
Solution: Check if the cursor position changed. (closes #4912)
Files: src/popupwin.c, src/structs.h, src/testdir/test_popupwin.vim,
src/testdir/dumps/Test_popupwin_cursorline_7.dump
*** ../vim-8.1.2008/src/popupwin.c 2019-09-07 14:33:32.849745196 +0200
--- src/popupwin.c 2019-09-08 16:41:57.788649091 +0200
***************
*** 542,549 ****
{
if (wp->w_cursor.lnum < wp->w_topline)
wp->w_topline = wp->w_cursor.lnum;
! else if (wp->w_cursor.lnum >= wp->w_botline)
wp->w_topline = wp->w_cursor.lnum - wp->w_height + 1;
// Don't use "firstline" now.
wp->w_firstline = 0;
--- 542,556 ----
{
if (wp->w_cursor.lnum < wp->w_topline)
wp->w_topline = wp->w_cursor.lnum;
! else if (wp->w_cursor.lnum >= wp->w_botline
! && (curwin->w_valid & VALID_BOTLINE))
! {
wp->w_topline = wp->w_cursor.lnum - wp->w_height + 1;
+ if (wp->w_topline < 1)
+ wp->w_topline = 1;
+ else if (wp->w_topline > wp->w_buffer->b_ml.ml_line_count)
+ wp->w_topline = wp->w_buffer->b_ml.ml_line_count;
+ }
// Don't use "firstline" now.
wp->w_firstline = 0;
***************
*** 593,598 ****
--- 600,606 ----
}
else
sign_undefine_by_name(sign_name, FALSE);
+ wp->w_popup_last_curline = wp->w_cursor.lnum;
}
/*
***************
*** 1059,1064 ****
--- 1067,1077 ----
wp->w_popup_leftoff = 0;
wp->w_popup_rightoff = 0;
+ // May need to update the "cursorline" highlighting, which may also change
+ // "topline"
+ if (wp->w_popup_last_curline != wp->w_cursor.lnum)
+ popup_highlight_curline(wp);
+
// If no line was specified default to vertical centering.
if (wantline == 0)
center_vert = TRUE;
***************
*** 1159,1165 ****
// start at the desired first line
if (wp->w_firstline > 0)
wp->w_topline = wp->w_firstline;
! if (wp->w_topline > wp->w_buffer->b_ml.ml_line_count)
wp->w_topline = wp->w_buffer->b_ml.ml_line_count;
// Compute width based on longest text line and the 'wrap' option.
--- 1172,1180 ----
// start at the desired first line
if (wp->w_firstline > 0)
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)
wp->w_topline = wp->w_buffer->b_ml.ml_line_count;
// Compute width based on longest text line and the 'wrap' option.
***************
*** 2998,3003 ****
--- 3013,3019 ----
* Return TRUE if popup_adjust_position() needs to be called for "wp".
* That is when the buffer in the popup was changed, or the popup is following
* a textprop and the referenced buffer was changed.
+ * Or when the cursor line changed and "cursorline" is set.
*/
static int
popup_need_position_adjust(win_T *wp)
***************
*** 3007,3013 ****
if (win_valid(wp->w_popup_prop_win))
return wp->w_popup_prop_changedtick
!= CHANGEDTICK(wp->w_popup_prop_win->w_buffer)
! || wp->w_popup_prop_topline != wp->w_popup_prop_win->w_topline;
return FALSE;
}
--- 3023,3031 ----
if (win_valid(wp->w_popup_prop_win))
return wp->w_popup_prop_changedtick
!= CHANGEDTICK(wp->w_popup_prop_win->w_buffer)
! || wp->w_popup_prop_topline != wp->w_popup_prop_win->w_topline
! || ((wp->w_popup_flags & POPF_CURSORLINE)
! && wp->w_cursor.lnum != wp->w_popup_last_curline);
return FALSE;
}
*** ../vim-8.1.2008/src/structs.h 2019-09-04 11:51:14.281537844 +0200
--- src/structs.h 2019-09-08 16:19:47.873227777 +0200
***************
*** 3050,3055 ****
--- 3050,3057 ----
int w_popup_prop_topline; // w_topline of window with
// w_popup_prop_type when position was
// computed
+ linenr_T w_popup_last_curline; // last known w_cursor.lnum of window
+ // with "cursorline" set
callback_T w_close_cb; // popup close callback
callback_T w_filter_cb; // popup filter callback
int w_filter_mode; // mode when filter callback is used
*** ../vim-8.1.2008/src/testdir/test_popupwin.vim 2019-09-07 14:06:34.328256587 +0200
--- src/testdir/test_popupwin.vim 2019-09-08 16:46:58.519627343 +0200
***************
*** 2306,2311 ****
--- 2306,2325 ----
call term_sendkeys(buf, "x")
call StopVimInTerminal(buf)
+ " ---------
+ " Cursor in second line when creating the popup
+ " ---------
+ let lines =<< trim END
+ let winid = popup_create(['111', '222', '333'], #{
+ \ cursorline : 1,
+ \ })
+ call win_execute(winid, "2")
+ END
+ call writefile(lines, 'XtestPopupCursorLine')
+ let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
+ call VerifyScreenDump(buf, 'Test_popupwin_cursorline_7', {})
+ call StopVimInTerminal(buf)
+
call delete('XtestPopupCursorLine')
endfunc
*** ../vim-8.1.2008/src/testdir/dumps/Test_popupwin_cursorline_7.dump 2019-09-08 16:55:50.925791512 +0200
--- src/testdir/dumps/Test_popupwin_cursorline_7.dump 2019-09-08 16:47:09.563589519 +0200
***************
*** 0 ****
--- 1,10 ----
+ > +0&#ffffff0@74
+ |~+0#4040ff13&| @73
+ |~| @73
+ |~| @34|1+0#0000001#ffd7ff255@2| +0#4040ff13#ffffff0@35
+ |~| @34|2+0#0000001#e0e0e08@2| +0#4040ff13#ffffff0@35
+ |~| @34|3+0#0000001#ffd7ff255@2| +0#4040ff13#ffffff0@35
+ |~| @73
+ |~| @73
+ |~| @73
+ | +0#0000000&@56|0|,|0|-|1| @8|A|l@1|
*** ../vim-8.1.2008/src/version.c 2019-09-08 15:27:17.552004765 +0200
--- src/version.c 2019-09-08 16:55:57.021770375 +0200
***************
*** 759,760 ****
--- 759,762 ----
{ /* Add new patch number below this line */
+ /**/
+ 2009,
/**/
--
hundred-and-one symptoms of being an internet addict:
219. Your spouse has his or her lawyer deliver the divorce papers...
via e-mail.
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language --
http://www.Zimbu.org ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///