]> granicus.if.org Git - vim/commitdiff
patch 9.0.1273: "1v" may select block with wrong size v9.0.1273
authorBram Moolenaar <Bram@vim.org>
Wed, 1 Feb 2023 17:33:18 +0000 (17:33 +0000)
committerBram Moolenaar <Bram@vim.org>
Wed, 1 Feb 2023 17:33:18 +0000 (17:33 +0000)
Problem:    "1v" may select block with wrong size. (Evgeni Chasnovski)
Solution:   Compute "curswant" in the right line. (closes #11925)

src/normal.c
src/testdir/test_visual.vim
src/version.c

index 0bd6655f2dc57ce68c163177868474551ee96dbd..9a3006705cb4ce33b27757a4ed68026fff4c3394 100644 (file)
@@ -5493,8 +5493,13 @@ 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_force();
-               curwin->w_curswant += + resel_VIsual_vcol * cap->count0 - 1;
+               curwin->w_curswant += resel_VIsual_vcol * cap->count0 - 1;
+               curwin->w_cursor.lnum = lnum;
                coladvance(curwin->w_curswant);
            }
            else
index a56c28854fc59b20a020709938bec092817a2d19..295e16f93d9d9965a0b7775f9c16dde447b9792e 100644 (file)
@@ -1318,6 +1318,17 @@ func Test_visual_block_with_substitute()
 endfunc
 
 func Test_visual_reselect_with_count()
+  enew
+  call setline(1, ['aaaaaa', '✗ bbbb', '✗ bbbb'])
+  exe "normal! 2Gw\<C-V>jed"
+  exe "normal! gg0lP"
+  call assert_equal(['abbbbaaaaa', '✗bbbb ', '✗ '], getline(1, '$'))
+
+  exe "normal! 1vr."
+  call assert_equal(['a....aaaaa', '✗.... ', '✗ '], getline(1, '$'))
+
+  bwipe!
+
   " this was causing an illegal memory access
   let lines =<< trim END
 
index dc3fad59d2c269610637a7c478209a5d093633df..ff2105c87a08a97ec63ae643bb1af7144290ed67 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1273,
 /**/
     1272,
 /**/