Merge pull request #17821 from zeertzjq/vim-patch-cursorline

vim-patch:8.2.{4591,4614}: cursorline redrawing
This commit is contained in:
zeertzjq 2022-03-24 20:28:46 +08:00 committed by GitHub
commit 3b28bd57f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 89 additions and 36 deletions

View File

@ -119,7 +119,6 @@ void nvim_win_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err)
update_topline_win(win); update_topline_win(win);
redraw_later(win, VALID); redraw_later(win, VALID);
redraw_for_cursorline(win);
win->w_redr_status = true; win->w_redr_status = true;
} }

View File

@ -95,11 +95,6 @@ static void comp_botline(win_T *wp)
win_check_anchored_floats(wp); win_check_anchored_floats(wp);
} }
void reset_cursorline(void)
{
curwin->w_last_cursorline = 0;
}
// Redraw when w_cline_row changes and 'relativenumber' or 'cursorline' is set. // Redraw when w_cline_row changes and 'relativenumber' or 'cursorline' is set.
void redraw_for_cursorline(win_T *wp) void redraw_for_cursorline(win_T *wp)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
@ -107,21 +102,8 @@ void redraw_for_cursorline(win_T *wp)
if ((wp->w_p_rnu || win_cursorline_standout(wp)) if ((wp->w_p_rnu || win_cursorline_standout(wp))
&& (wp->w_valid & VALID_CROW) == 0 && (wp->w_valid & VALID_CROW) == 0
&& !pum_visible()) { && !pum_visible()) {
if (wp->w_p_rnu) { // win_line() will redraw the number column and cursorline only.
// win_line() will redraw the number column only. redraw_later(wp, VALID);
redraw_later(wp, VALID);
}
if (win_cursorline_standout(wp)) {
if (wp->w_redr_type <= VALID && wp->w_last_cursorline != 0) {
// "w_last_cursorline" may be outdated, worst case we redraw
// too much. This is optimized for moving the cursor around in
// the current window.
redrawWinline(wp, wp->w_last_cursorline);
redrawWinline(wp, wp->w_cursor.lnum);
} else {
redraw_later(wp, SOME_VALID);
}
}
} }
} }

View File

@ -1296,13 +1296,7 @@ static void normal_redraw(NormalState *s)
} }
// Might need to update for 'cursorline'. // Might need to update for 'cursorline'.
// When 'cursorlineopt' is "screenline" need to redraw always. check_redraw_cursorline();
if (curwin->w_p_cul
&& (curwin->w_last_cursorline != curwin->w_cursor.lnum
|| (curwin->w_p_culopt_flags & CULOPT_SCRLINE))
&& !char_avail()) {
redraw_later(curwin, VALID);
}
if (VIsual_active) { if (VIsual_active) {
update_curbuf(INVERTED); // update inverted part update_curbuf(INVERTED); // update inverted part

View File

@ -3962,11 +3962,8 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va
} else if ((int *)varp == &p_lnr) { } else if ((int *)varp == &p_lnr) {
// 'langnoremap' -> !'langremap' // 'langnoremap' -> !'langremap'
p_lrm = !p_lnr; p_lrm = !p_lnr;
} else if ((int *)varp == &curwin->w_p_cul && !value && old_value) {
// 'cursorline'
reset_cursorline();
// 'undofile'
} else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf) { } else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf) {
// 'undofile'
// Only take action when the option was set. When reset we do not // Only take action when the option was set. When reset we do not
// delete the undo file, the option may be set again without making // delete the undo file, the option may be set again without making
// any changes in between. // any changes in between.

View File

@ -1323,6 +1323,8 @@ static void win_update(win_T *wp, DecorProviders *providers)
DecorProviders line_providers; DecorProviders line_providers;
decor_providers_invoke_win(wp, providers, &line_providers, &provider_err); decor_providers_invoke_win(wp, providers, &line_providers, &provider_err);
bool cursorline_standout = win_cursorline_standout(wp);
for (;;) { for (;;) {
/* stop updating when reached the end of the window (check for _past_ /* stop updating when reached the end of the window (check for _past_
* the end of the window is at the end of the loop) */ * the end of the window is at the end of the loop) */
@ -1367,8 +1369,8 @@ static void win_update(win_T *wp, DecorProviders *providers)
// if lines were inserted or deleted // if lines were inserted or deleted
|| (wp->w_match_head != NULL || (wp->w_match_head != NULL
&& buf->b_mod_xlines != 0))))) && buf->b_mod_xlines != 0)))))
|| (wp->w_p_cul && (lnum == wp->w_cursor.lnum || (cursorline_standout && lnum == wp->w_cursor.lnum)
|| lnum == wp->w_last_cursorline))) { || lnum == wp->w_last_cursorline) {
if (lnum == mod_top) { if (lnum == mod_top) {
top_to_mod = false; top_to_mod = false;
} }
@ -1601,6 +1603,9 @@ static void win_update(win_T *wp, DecorProviders *providers)
* End of loop over all window lines. * End of loop over all window lines.
*/ */
// Now that the window has been redrawn with the old and new cursor line,
// update w_last_cursorline.
wp->w_last_cursorline = cursorline_standout ? wp->w_cursor.lnum : 0;
if (idx > wp->w_lines_valid) { if (idx > wp->w_lines_valid) {
wp->w_lines_valid = idx; wp->w_lines_valid = idx;
@ -2380,8 +2385,6 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc
} }
area_highlighting = true; area_highlighting = true;
} }
// Update w_last_cursorline even if Visual mode is active.
wp->w_last_cursorline = wp->w_cursor.lnum;
} }
memset(sattrs, 0, sizeof(sattrs)); memset(sattrs, 0, sizeof(sattrs));
@ -7615,3 +7618,15 @@ win_T *get_win_by_grid_handle(handle_T handle)
return NULL; return NULL;
} }
/// Check if the cursor moved and 'cursorline' is set. Mark for a VALID redraw
/// if needed.
void check_redraw_cursorline(void)
{
// When 'cursorlineopt' is "screenline" need to redraw always.
if (curwin->w_p_cul
&& (curwin->w_last_cursorline != curwin->w_cursor.lnum
|| (curwin->w_p_culopt_flags & CULOPT_SCRLINE))
&& !char_avail()) {
redraw_later(curwin, VALID);
}
}

View File

@ -268,4 +268,30 @@ END
call delete('Xtextfile') call delete('Xtextfile')
endfunc endfunc
func Test_cursorline_callback()
CheckScreendump
CheckFeature timers
let lines =<< trim END
call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'])
set cursorline
call cursor(4, 1)
func Func(timer)
call cursor(2, 1)
endfunc
call timer_start(300, 'Func')
END
call writefile(lines, 'Xcul_timer')
let buf = RunVimInTerminal('-S Xcul_timer', #{rows: 8})
call TermWait(buf, 310)
call VerifyScreenDump(buf, 'Test_cursorline_callback_1', {})
call StopVimInTerminal(buf)
call delete('Xcul_timer')
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@ -1081,6 +1081,46 @@ describe('CursorLine and CursorLineNr highlights', function()
]]) ]])
end) end)
it('is updated if cursor is moved up from timer vim-patch:8.2.4591', function()
local screen = Screen.new(50, 8)
screen:set_default_attr_ids({
[1] = {background = Screen.colors.Gray90}, -- CursorLine
[2] = {bold = true, foreground = Screen.colors.Blue1}, -- NonText
})
screen:attach()
exec([[
call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'])
set cursorline
call cursor(4, 1)
func Func(timer)
call cursor(2, 1)
endfunc
call timer_start(300, 'Func')
]])
screen:expect({grid = [[
aaaaa |
bbbbb |
ccccc |
{1:^ddddd }|
{2:~ }|
{2:~ }|
{2:~ }|
|
]], timeout = 100})
screen:expect({grid = [[
aaaaa |
{1:^bbbbb }|
ccccc |
ddddd |
{2:~ }|
{2:~ }|
{2:~ }|
|
]]})
end)
it('with split windows in diff mode', function() it('with split windows in diff mode', function()
local screen = Screen.new(50,12) local screen = Screen.new(50,12)
screen:set_default_attr_ids({ screen:set_default_attr_ids({