summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-09-08 17:12:01 +0200
committerBram Moolenaar <Bram@vim.org>2019-09-08 17:12:01 +0200
commit3d2a3cbce873af861031a01e02694dcfae0c4582 (patch)
treed42cb9c8278b7bf9564b0c490fb994a53dd6c704 /src
parent4544bd2f247425c9dd743c76618dd70f53c72538 (diff)
downloadvim-git-3d2a3cbce873af861031a01e02694dcfae0c4582.tar.gz
patch 8.1.2009: cursorline highlighting not updated in popup windowv8.1.2009
Problem: Cursorline highlighting not updated in popup window. (Marko Mahnič) Solution: Check if the cursor position changed. (closes #4912)
Diffstat (limited to 'src')
-rw-r--r--src/popupwin.c24
-rw-r--r--src/structs.h2
-rw-r--r--src/testdir/dumps/Test_popupwin_cursorline_7.dump10
-rw-r--r--src/testdir/test_popupwin.vim14
-rw-r--r--src/version.c2
5 files changed, 49 insertions, 3 deletions
diff --git a/src/popupwin.c b/src/popupwin.c
index 7fb9792f5..066720040 100644
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -542,8 +542,15 @@ popup_show_curline(win_T *wp)
{
if (wp->w_cursor.lnum < wp->w_topline)
wp->w_topline = wp->w_cursor.lnum;
- else if (wp->w_cursor.lnum >= wp->w_botline)
+ 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,6 +600,7 @@ popup_highlight_curline(win_T *wp)
}
else
sign_undefine_by_name(sign_name, FALSE);
+ wp->w_popup_last_curline = wp->w_cursor.lnum;
}
/*
@@ -1059,6 +1067,11 @@ popup_adjust_position(win_T *wp)
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,7 +1172,9 @@ popup_adjust_position(win_T *wp)
// 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)
+ 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,6 +3013,7 @@ check_popup_unhidden(win_T *wp)
* 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,7 +3023,9 @@ popup_need_position_adjust(win_T *wp)
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_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;
}
diff --git a/src/structs.h b/src/structs.h
index ce618b903..0e61f87dd 100644
--- a/src/structs.h
+++ b/src/structs.h
@@ -3050,6 +3050,8 @@ struct window_S
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
diff --git a/src/testdir/dumps/Test_popupwin_cursorline_7.dump b/src/testdir/dumps/Test_popupwin_cursorline_7.dump
new file mode 100644
index 000000000..15eb0be86
--- /dev/null
+++ b/src/testdir/dumps/Test_popupwin_cursorline_7.dump
@@ -0,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|
diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim
index cbfc7d2d7..a33816985 100644
--- a/src/testdir/test_popupwin.vim
+++ b/src/testdir/test_popupwin.vim
@@ -2306,6 +2306,20 @@ func Test_popup_cursorline()
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
diff --git a/src/version.c b/src/version.c
index b797a59d1..6f8855a82 100644
--- a/src/version.c
+++ b/src/version.c
@@ -758,6 +758,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2009,
+/**/
2008,
/**/
2007,