From 4baeb96c1bb66c845b4bc58482df4e601485eec3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 28 Mar 2022 04:43:51 +0800 Subject: vim-patch:8.2.4638: superfluous check if a redraw is needed for 'cursorline' Problem: Superfluous check if a redraw is needed for 'cursorline'. Solution: Remove check_redraw_cursorline(). (closes vim/vim#10030, closes vim/vim#10029) https://github.com/vim/vim/commit/3e559cd88486ffab6b6fb4e0921b4600d137a617 redraw_after_callback() is N/A. Omits changes that just revert code from patch 8.2.4630. --- src/nvim/move.c | 29 +++++++++++++++++++---------- src/nvim/normal.c | 3 --- src/nvim/screen.c | 13 ------------- src/nvim/testdir/test_highlight.vim | 25 +++++++++++++++++++++++++ src/nvim/testdir/test_number.vim | 25 +++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/nvim/move.c b/src/nvim/move.c index 751e0046bc..9b35a7da0a 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -95,7 +95,7 @@ static void comp_botline(win_T *wp) win_check_anchored_floats(wp); } -// 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) FUNC_ATTR_NONNULL_ALL { @@ -107,6 +107,22 @@ void redraw_for_cursorline(win_T *wp) } } +/// Redraw when w_virtcol changes and 'cursorcolumn' is set or 'cursorlineopt' +/// contains "screenline". +static void redraw_for_cursorcolumn(win_T *wp) + FUNC_ATTR_NONNULL_ALL +{ + if ((wp->w_valid & VALID_VIRTCOL) == 0 && !pum_visible()) { + if (wp->w_p_cuc) { + // When 'cursorcolumn' is set need to redraw with SOME_VALID. + redraw_later(wp, SOME_VALID); + } else if (wp->w_p_cul && (wp->w_p_culopt_flags & CULOPT_SCRLINE)) { + // When 'cursorlineopt' contains "screenline" need to redraw with VALID. + redraw_later(wp, VALID); + } + } +} + /* * Update curwin->w_topline and redraw if necessary. * Used to update the screen before printing a message. @@ -623,11 +639,8 @@ void validate_virtcol_win(win_T *wp) check_cursor_moved(wp); if (!(wp->w_valid & VALID_VIRTCOL)) { getvvcol(wp, &wp->w_cursor, NULL, &(wp->w_virtcol), NULL); + redraw_for_cursorcolumn(wp); wp->w_valid |= VALID_VIRTCOL; - if (wp->w_p_cuc - && !pum_visible()) { - redraw_later(wp, SOME_VALID); - } } } @@ -930,11 +943,7 @@ void curs_columns(win_T *wp, int may_scroll) redraw_later(wp, NOT_VALID); } - // Redraw when w_virtcol changes and 'cursorcolumn' is set - if (wp->w_p_cuc && (wp->w_valid & VALID_VIRTCOL) == 0 - && !pum_visible()) { - redraw_later(wp, SOME_VALID); - } + redraw_for_cursorcolumn(curwin); // now w_leftcol is valid, avoid check_cursor_moved() thinking otherwise wp->w_valid_leftcol = wp->w_leftcol; diff --git a/src/nvim/normal.c b/src/nvim/normal.c index e773351d63..6c7595d1a4 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -1295,9 +1295,6 @@ static void normal_redraw(NormalState *s) redrawWinline(curwin, curwin->w_cursor.lnum); } - // Might need to update for 'cursorline'. - check_redraw_cursorline(); - if (VIsual_active) { update_curbuf(INVERTED); // update inverted part } else if (must_redraw) { diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 41a129dba9..67eee55c51 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -7617,16 +7617,3 @@ win_T *get_win_by_grid_handle(handle_T handle) } 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); - } -} diff --git a/src/nvim/testdir/test_highlight.vim b/src/nvim/testdir/test_highlight.vim index aa7b3a225b..6387ec62af 100644 --- a/src/nvim/testdir/test_highlight.vim +++ b/src/nvim/testdir/test_highlight.vim @@ -597,6 +597,31 @@ func Test_cursorline_with_visualmode() call delete('Xtest_cursorline_with_visualmode') endfunc +func Test_cursorcolumn_callback() + CheckScreendump + CheckFeature timers + + let lines =<< trim END + call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd']) + set cursorcolumn + call cursor(4, 5) + + func Func(timer) + call cursor(1, 1) + endfunc + + call timer_start(300, 'Func') + END + call writefile(lines, 'Xcuc_timer') + + let buf = RunVimInTerminal('-S Xcuc_timer', #{rows: 8}) + call TermWait(buf, 310) + call VerifyScreenDump(buf, 'Test_cursorcolumn_callback_1', {}) + + call StopVimInTerminal(buf) + call delete('Xcuc_timer') +endfunc + func Test_colorcolumn() CheckScreendump diff --git a/src/nvim/testdir/test_number.vim b/src/nvim/testdir/test_number.vim index dfbdc0bffd..521b0cf706 100644 --- a/src/nvim/testdir/test_number.vim +++ b/src/nvim/testdir/test_number.vim @@ -298,6 +298,31 @@ func Test_relativenumber_colors() call delete('XTest_relnr') endfunc +func Test_relativenumber_callback() + CheckScreendump + CheckFeature timers + + let lines =<< trim END + call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd']) + set relativenumber + call cursor(4, 1) + + func Func(timer) + call cursor(1, 1) + endfunc + + call timer_start(300, 'Func') + END + call writefile(lines, 'Xrnu_timer') + + let buf = RunVimInTerminal('-S Xrnu_timer', #{rows: 8}) + call TermWait(buf, 310) + call VerifyScreenDump(buf, 'Test_relativenumber_callback_1', {}) + + call StopVimInTerminal(buf) + call delete('Xrnu_timer') +endfunc + " Test for displaying line numbers with 'rightleft' func Test_number_rightleft() CheckFeature rightleft -- cgit From ab02b28b4e14ecd22facab9377ea71aff2ffdfdb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 28 Mar 2022 05:10:15 +0800 Subject: vim-patch:8.2.4630: 'cursorline' not always updated with 'culopt' is "screenline" Problem: 'cursorline' not always updated with 'cursorlineopt' is "screenline". Solution: Call check_redraw_cursorline() more often. (closes vim/vim#10013) https://github.com/vim/vim/commit/bf269ed0b0bd8414eea7bea17465b2738a9a2b55 Code was reverted in patch 8.2.4638, so this just ports the test. --- src/nvim/testdir/test_cursorline.vim | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src') diff --git a/src/nvim/testdir/test_cursorline.vim b/src/nvim/testdir/test_cursorline.vim index bf049ec779..7e97df6027 100644 --- a/src/nvim/testdir/test_cursorline.vim +++ b/src/nvim/testdir/test_cursorline.vim @@ -293,5 +293,26 @@ func Test_cursorline_callback() call delete('Xcul_timer') endfunc +func Test_cursorline_screenline_update() + CheckScreendump + + let lines =<< trim END + call setline(1, repeat('xyz ', 30)) + set cursorline cursorlineopt=screenline + inoremap call cursor(1, 1) + END + call writefile(lines, 'Xcul_screenline') + + let buf = RunVimInTerminal('-S Xcul_screenline', #{rows: 8}) + call term_sendkeys(buf, "A") + call VerifyScreenDump(buf, 'Test_cursorline_screenline_1', {}) + call term_sendkeys(buf, "\") + call VerifyScreenDump(buf, 'Test_cursorline_screenline_2', {}) + call term_sendkeys(buf, "\") + + call StopVimInTerminal(buf) + call delete('Xcul_screenline') +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit