From 7b973c71ea845c9bcc6d98e101ad5a7956cb5802 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 6 Jun 2023 19:24:42 +0800 Subject: [PATCH] fix(statusline): redraw when VIsual_mode changes (#23933) --- src/nvim/buffer_defs.h | 3 +- src/nvim/drawscreen.c | 8 +++- test/functional/ui/statusline_spec.lua | 54 +++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index f3f98bbd17..e3e457cea6 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -1292,8 +1292,9 @@ struct window_S { linenr_T w_stl_line_count; // line count when last redrawn int w_stl_topfill; // topfill when last redrawn char w_stl_empty; // true if elements show 0-1 (empty line) - int w_stl_state; // State when last redrawn int w_stl_recording; // reg_recording when last redrawn + int w_stl_state; // get_real_state() when last redrawn + int w_stl_visual_mode; // VIsual_mode when last redrawn int w_alt_fnum; // alternate file (for # and CTRL-^) diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c index 28a029d758..3f024c507b 100644 --- a/src/nvim/drawscreen.c +++ b/src/nvim/drawscreen.c @@ -839,7 +839,8 @@ void show_cursor_info_later(bool force) || curwin->w_topfill != curwin->w_stl_topfill || empty_line != curwin->w_stl_empty || reg_recording != curwin->w_stl_recording - || state != curwin->w_stl_state) { + || state != curwin->w_stl_state + || (VIsual_active && VIsual_mode != curwin->w_stl_visual_mode)) { if (curwin->w_status_height || global_stl_height()) { curwin->w_redr_status = true; } else { @@ -862,8 +863,11 @@ void show_cursor_info_later(bool force) curwin->w_stl_topline = curwin->w_topline; curwin->w_stl_line_count = curwin->w_buffer->b_ml.ml_line_count; curwin->w_stl_topfill = curwin->w_topfill; - curwin->w_stl_state = state; curwin->w_stl_recording = reg_recording; + curwin->w_stl_state = state; + if (VIsual_active) { + curwin->w_stl_visual_mode = VIsual_mode; + } } /// @return true when postponing displaying the mode message: when not redrawing diff --git a/test/functional/ui/statusline_spec.lua b/test/functional/ui/statusline_spec.lua index 5afa912be6..c47b26f55e 100644 --- a/test/functional/ui/statusline_spec.lua +++ b/test/functional/ui/statusline_spec.lua @@ -627,11 +627,19 @@ it('K_EVENT does not trigger a statusline redraw unnecessarily', function() eq(1, eval('g:counter < 50'), 'g:counter=' .. eval('g:counter')) end) -it('statusline is redrawn on recording state change #22683', function() +it('statusline is redrawn on various state changes', function() clear() local screen = Screen.new(40, 4) screen:attach() + + -- recording state change #22683 command('set ls=2 stl=%{repeat(reg_recording(),5)}') + screen:expect([[ + ^ | + ~ | + | + | + ]]) feed('qQ') screen:expect([[ ^ | @@ -639,6 +647,50 @@ it('statusline is redrawn on recording state change #22683', function() QQQQQ | recording @Q | ]]) + feed('q') + screen:expect([[ + ^ | + ~ | + | + | + ]]) + + -- Visual mode change #23932 + command('set ls=2 stl=%{mode(1)}') + screen:expect([[ + ^ | + ~ | + n | + | + ]]) + feed('v') + screen:expect([[ + ^ | + ~ | + v | + -- VISUAL -- | + ]]) + feed('V') + screen:expect([[ + ^ | + ~ | + V | + -- VISUAL LINE -- | + ]]) + feed('') + screen:expect([[ + ^ | + ~ | + ^V | + -- VISUAL BLOCK -- | + ]]) + feed('') + screen:expect([[ + ^ | + ~ | + n | + | + ]]) end) it('ruler is redrawn in cmdline with redrawstatus #22804', function()