]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0796: Visual block reselection wrong with 'virtualedit' v9.2.0796
authorzeertzjq <zeertzjq@outlook.com>
Sat, 18 Jul 2026 14:14:12 +0000 (14:14 +0000)
committerChristian Brabandt <cb@256bit.org>
Sat, 18 Jul 2026 14:14:12 +0000 (14:14 +0000)
Problem:  Visual block reselection wrong with 'virtualedit' when line
          lengths are different (Alex Yang, after 8.2.3494).
Solution: Set the entire cursor position to old position when computing
          target curswant, since the check_cursor() added in 8.2.3494
          may change cursor column as well (zeertzjq).

fixes:  #20746
closes: #20748

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/normal.c
src/testdir/test_visual.vim
src/version.c

index b803b88f6b34336ecb19c0005f7a94bb1e31174a..08b9e9f0cfe0852d79fb92d9a0bf660fc0ee6146 100644 (file)
@@ -5579,13 +5579,12 @@ nv_visual(cmdarg_T *cap)
            }
            else if (VIsual_mode == Ctrl_V)
            {
-               // Update curswant on the original line, that is where "col" is
-               // valid.
-               linenr_T lnum = curwin->w_cursor.lnum;
-               curwin->w_cursor.lnum = VIsual.lnum;
+               // Update curswant at the original cursor position.
+               pos_T tmp_cursor = curwin->w_cursor;
+               curwin->w_cursor = VIsual;
                update_curswant_force();
                curwin->w_curswant += resel_VIsual_vcol * cap->count0 - 1;
-               curwin->w_cursor.lnum = lnum;
+               curwin->w_cursor = tmp_cursor;
                if (*p_sel == 'e')
                    ++curwin->w_curswant;
                coladvance(curwin->w_curswant);
index d92f651d9abd7fbec2d888aaae51b82ff0782936..beea4c431bebbf395118261b390fa54ac930d783 100644 (file)
@@ -1004,6 +1004,28 @@ func Test_virtualedit_visual_block()
   bwipe!
 endfunc
 
+func Test_virtualedit_visual_block_reselect()
+  set ve=all
+  new
+  call append(0, ['###', '###', '###', '#####'])
+  call cursor(1, 1)
+  exe "norm! \<C-V>lljj"
+  call assert_equal([0, 3, 3, 0], getpos('.'))
+  call assert_equal([0, 1, 1, 0], getpos('v'))
+  norm! y
+  call assert_equal(['###', '###', '###'], getreg('"', v:true, v:true))
+  call cursor(2, 6)
+  call assert_equal([0, 2, 4, 2], getpos('.'))
+  norm! 1v
+  call assert_equal([0, 4, 6, 2], getpos('.'))
+  call assert_equal([0, 2, 4, 2], getpos('v'))
+  norm! r!
+  call assert_equal(['###  !!!', '###  !!!', '#####!!!'], getline(2, 4))
+
+  bwipe!
+  set ve&
+endfunc
+
 " Test for changing case
 func Test_visual_change_case()
   new
index e0861aa389d15076f72b2463d0563e7c3d6af3eb..9a22bfa5194f507de8f451b68ed527ded0d945c7 100644 (file)
@@ -759,6 +759,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    796,
 /**/
     795,
 /**/