From 2b02dfa0202ce667f83474835759ca9d8103a9eb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 12 Dec 2025 09:38:11 +0800 Subject: [PATCH] vim-patch:9.1.1970: visual end column returns wrong value after block edit (#36923) Problem: visual end column returns wrong value after block edit Solution: update visual end column after block insert (phanium) fixes: vim/vim#18900 closes: vim/vim#18903 https://github.com/vim/vim/commit/fa3bdc2501faeae7f3211fc8559ded43e27b864c Co-authored-by: phanium <91544758+phanen@users.noreply.github.com> --- src/nvim/ops.c | 4 ++++ test/old/testdir/test_visual.vim | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 8fa867125b..900e17ba78 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -692,6 +692,10 @@ static void block_insert(oparg_T *oap, const char *s, size_t slen, bool b_insert // the insert in the first line. curbuf->b_op_end.lnum = oap->end.lnum; curbuf->b_op_end.col = offset; + if (curbuf->b_visual.vi_end.coladd) { + curbuf->b_visual.vi_end.col += curbuf->b_visual.vi_end.coladd; + curbuf->b_visual.vi_end.coladd = 0; + } } } // for all lnum diff --git a/test/old/testdir/test_visual.vim b/test/old/testdir/test_visual.vim index 4e04a567e3..9ee5bb8250 100644 --- a/test/old/testdir/test_visual.vim +++ b/test/old/testdir/test_visual.vim @@ -2826,4 +2826,17 @@ func Test_visual_pos_buffer_heap_overflow() bw! Xa Xb endfunc +" Test visual block pos update after block insert and gv +func Test_visual_block_pos_update() + new + set virtualedit=block + call setline(1, ['aacccc', 'bb']) + exe "norm! e\jAa\gv" + call assert_equal([[0, 1, 6, 0], [0 , 2, 6, 0]], [getpos("v"), getpos(".")]) + normal! kj + call assert_equal([[0, 1, 6, 0], [0 , 2, 6, 0]], [getpos("v"), getpos(".")]) + set virtualedit= + bw! +endfunc + " vim: shiftwidth=2 sts=2 expandtab