From 4cc060bf44a806faed35c5b1e3b97e02b424e895 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 23 Oct 2025 11:27:23 +0800 Subject: [PATCH] fix(statusline): redraw if Visual selection other end changes (#36281) (cherry picked from commit af0f7b59b1fcd92e64841cb5da8a577e944ce5bb) --- src/nvim/buffer_defs.h | 1 + src/nvim/drawscreen.c | 6 +++++- test/functional/ui/statusline_spec.lua | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index c912f8dafd..1dde2c5101 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -1248,6 +1248,7 @@ struct window_S { 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 + pos_T w_stl_visual_pos; // VIsual 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 088cf4f2dc..95b6e97882 100644 --- a/src/nvim/drawscreen.c +++ b/src/nvim/drawscreen.c @@ -915,7 +915,10 @@ void show_cursor_info_later(bool force) || empty_line != curwin->w_stl_empty || reg_recording != curwin->w_stl_recording || state != curwin->w_stl_state - || (VIsual_active && VIsual_mode != curwin->w_stl_visual_mode)) { + || (VIsual_active && (VIsual_mode != curwin->w_stl_visual_mode + || VIsual.lnum != curwin->w_stl_visual_pos.lnum + || VIsual.col != curwin->w_stl_visual_pos.col + || VIsual.coladd != curwin->w_stl_visual_pos.coladd))) { if (curwin->w_status_height || global_stl_height()) { curwin->w_redr_status = true; } else { @@ -939,6 +942,7 @@ void show_cursor_info_later(bool force) curwin->w_stl_state = state; if (VIsual_active) { curwin->w_stl_visual_mode = VIsual_mode; + curwin->w_stl_visual_pos = VIsual; } } diff --git a/test/functional/ui/statusline_spec.lua b/test/functional/ui/statusline_spec.lua index bd27c97430..78cd10b075 100644 --- a/test/functional/ui/statusline_spec.lua +++ b/test/functional/ui/statusline_spec.lua @@ -656,6 +656,28 @@ describe('statusline', function() ]]) feed('') screen:expect(s2) + + -- Visual selection other end change #36280 + exec([[ + function! DebugVisualSelection() + return printf("v %s %s", col("v"), col(".")) + endfunction + set statusline=%!DebugVisualSelection() + ]]) + feed('iabcv') + screen:expect([[ + ab^c | + {1:~ }|*5 + {3:v 3 3 }| + {5:-- VISUAL --} | + ]]) + feed('iw') + screen:expect([[ + {17:ab}^c | + {1:~ }|*5 + {3:v 1 3 }| + {5:-- VISUAL --} | + ]]) end) it('ruler is redrawn in cmdline with redrawstatus #22804', function()