]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0515: virtualedit=insert doesn't work during change operation v9.2.0515
authorzeertzjq <zeertzjq@outlook.com>
Fri, 22 May 2026 23:08:29 +0000 (23:08 +0000)
committerChristian Brabandt <cb@256bit.org>
Fri, 22 May 2026 23:08:29 +0000 (23:08 +0000)
Problem:  virtualedit=insert doesn't work during change operation
          (after 6.1.014).
Solution: Make virtual_op only affect virtualedit=block (zeertzjq).

related: neovim/neovim#35391
closes:  #20298

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

index 076593d6e0a817313a210ee5f773497024c74a2d..25dab5ed13770b72bf1a2086d6aa7afe6bedc563 100644 (file)
@@ -24,15 +24,16 @@ virtual_active(void)
 {
     unsigned int cur_ve_flags = get_ve_flags();
 
+    if (cur_ve_flags == VE_ALL
+           || ((cur_ve_flags & VE_INSERT) && (State & MODE_INSERT)))
+       return TRUE;
+
     // While an operator is being executed we return "virtual_op", because
     // VIsual_active has already been reset, thus we can't check for "block"
     // being used.
     if (virtual_op != MAYBE)
        return virtual_op;
-    return (cur_ve_flags == VE_ALL
-           || ((cur_ve_flags & VE_BLOCK) && VIsual_active
-                                                     && VIsual_mode == Ctrl_V)
-           || ((cur_ve_flags & VE_INSERT) && (State & MODE_INSERT)));
+    return (cur_ve_flags & VE_BLOCK) && VIsual_active && VIsual_mode == Ctrl_V;
 }
 
 /*
index 7819025f6bf540d22b8cdb99b65a2a7cb4f4c0db..902bbbfd1e0a4354a914640ee8701ad9b9a2a0ca 100644 (file)
@@ -753,4 +753,39 @@ func Test_virtualedit_getpos_stable_past_eol_after_visual()
   bwipe!
 endfunc
 
+func Test_virtualedit_insert()
+  new
+  set virtualedit=insert
+
+  call feedkeys("ifoobar\<Right>\<Right>\<Right>\<Right>baz\<Esc>", 'tnix')
+  call assert_equal('foobar    baz', getline(1))
+
+  call feedkeys("ccFOOBAR\<Right>\<Right>\<Right>\<Right>BAZ\<Esc>", 'tnix')
+  call assert_equal('FOOBAR    BAZ', getline(1))
+
+  set virtualedit&
+  bwipe!
+endfunc
+
+func Test_set_virtualedit_on_mode_change()
+  new
+  set virtualedit=all
+  augroup testing
+    au ModeChanged n:* set virtualedit=onemore
+    au ModeChanged *:n set virtualedit=all
+    au ModeChanged i:* call cursor(getpos("'^")[1:])
+  augroup END
+
+  call feedkeys("ilkj\<Esc>", 'tnix')
+  call assert_equal([0, 1, 4, 0], getpos('.'))
+
+  call feedkeys("cclkj\<Esc>", 'tnix')
+  call assert_equal([0, 1, 4, 0], getpos('.'))
+
+  au! testing ModeChanged
+  augroup! testing
+  set virtualedit&
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index a2674417da790a46b0981ef6dacb7987104914fc..dd6dc159858340a1b97210cf231c479c4bee2322 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    515,
 /**/
     514,
 /**/