]> granicus.if.org Git - vim/commitdiff
patch 8.2.3684: blockwise insert does not handle autoindent properly v8.2.3684
authorBram Moolenaar <Bram@vim.org>
Sat, 27 Nov 2021 13:28:24 +0000 (13:28 +0000)
committerBram Moolenaar <Bram@vim.org>
Sat, 27 Nov 2021 13:28:24 +0000 (13:28 +0000)
Problem:    Blockwise insert does not handle autoindent properly.
Solution:   Adjust text column for indent. (closes #9229)

src/ops.c
src/testdir/test_blockedit.vim
src/version.c

index d6190641da552618b48a97ca236c302f2064934d..354b2e251a2a1dcdd1ae3624565ed154b2771dd2 100644 (file)
--- a/src/ops.c
+++ b/src/ops.c
@@ -1627,6 +1627,10 @@ op_insert(oparg_T *oap, long count1)
                    --bd2.textlen;
            }
            bd.textcol = bd2.textcol;
+           if (did_indent && bd.textcol > ind_pre)
+               // If the insert was in the indent then include the indent
+               // change in the new text, otherwise don't.
+               bd.textcol += ind_post - ind_pre;
            bd.textlen = bd2.textlen;
        }
 
index 29e24759fa7e20a04a2266d5d4eaac816da6eda4..216238a52879fe775676d4a5de3bd6239d362477 100644 (file)
@@ -14,6 +14,33 @@ func Test_blockinsert_indent()
   bwipe!
 endfunc
 
+func Test_blockinsert_autoindent()
+  new
+  let lines =<< trim END
+      var d = {
+      a: () => 0,
+      b: () => 0,
+      c: () => 0,
+      }
+  END
+  call setline(1, lines)
+  filetype plugin indent on
+  setlocal sw=2 et ft=vim
+  setlocal indentkeys+=:
+  exe "norm! 2Gf)\<c-v>2jA: asdf\<esc>"
+  let expected =<< trim END
+      var d = {
+        a: (): asdf => 0,
+      b: (): asdf => 0,
+      c: (): asdf => 0,
+      }
+  END
+  call assert_equal(expected, getline(1, 5))
+
+  filetype off
+  bwipe!
+endfunc
+
 func Test_blockinsert_delete()
   new
   let _bs = &bs
index 7361d90f26a1357c9ba35527f4df8d856329a7c9..35afaedae44532e40befad1017b739bc57bc1ea1 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3684,
 /**/
     3683,
 /**/