]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.0.1682: auto indenting breaks inserting a block v8.0.1682
authorBram Moolenaar <Bram@vim.org>
Tue, 10 Apr 2018 11:15:47 +0000 (13:15 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 10 Apr 2018 11:15:47 +0000 (13:15 +0200)
Problem:    Auto indenting breaks inserting a block.
Solution:   Do not check for cursor movement if indent was changed. (Christian
            Brabandt, closes #2778)

src/Makefile
src/ops.c
src/testdir/Make_all.mak
src/testdir/test_blockedit.vim [new file with mode: 0644]
src/version.c

index a294ec0252324bc553d4d5e31cd8a606a0604aae..e7d0b38f08f981ec219bf9435599c942c094fdaf 100644 (file)
@@ -2127,6 +2127,7 @@ test_arglist \
        test_autocmd \
        test_autoload \
        test_backspace_opt \
+       test_blockedit \
        test_breakindent \
        test_bufline \
        test_bufwintabinfo \
index b1c1d369350a57df5988e758e3d025e681d6502e..fe29e8ae74c007b9f41630d189e47dc45ba42464 100644 (file)
--- a/src/ops.c
+++ b/src/ops.c
@@ -1093,7 +1093,7 @@ do_record(int c)
 
     if (Recording == FALSE)        /* start recording */
     {
-                       /* registers 0-9, a-z and " are allowed */
+       /* registers 0-9, a-z and " are allowed */
        if (c < 0 || (!ASCII_ISALNUM(c) && c != '"'))
            retval = FAIL;
        else
@@ -2702,6 +2702,7 @@ op_insert(oparg_T *oap, long count1)
     if (oap->block_mode)
     {
        struct block_def        bd2;
+       int                     did_indent = FALSE;
 
        /* If indent kicked in, the firstline might have changed
         * but only do that, if the indent actually increased. */
@@ -2710,11 +2711,14 @@ op_insert(oparg_T *oap, long count1)
        {
            bd.textcol += ind_post - ind_pre;
            bd.start_vcol += ind_post - ind_pre;
+           did_indent = TRUE;
        }
 
        /* The user may have moved the cursor before inserting something, try
-        * to adjust the block for that. */
-       if (oap->start.lnum == curbuf->b_op_start_orig.lnum && !bd.is_MAX)
+        * to adjust the block for that.  But only do it, if the difference
+        * does not come from indent kicking in. */
+       if (oap->start.lnum == curbuf->b_op_start_orig.lnum
+                                                 && !bd.is_MAX && !did_indent)
        {
            if (oap->op_type == OP_INSERT
                    && oap->start.col
index 159bf1ece6ac1c0929f656b577ad647e2f3f3f31..b0bfe2615ac632620f36ac8836995b3ae268be9f 100644 (file)
@@ -72,6 +72,7 @@ NEW_TESTS = test_arabic.res \
            test_autocmd.res \
            test_autoload.res \
            test_backspace_opt.res \
+           test_blockedit.res \
            test_breakindent.res \
            test_bufwintabinfo.res \
            test_cdo.res \
diff --git a/src/testdir/test_blockedit.vim b/src/testdir/test_blockedit.vim
new file mode 100644 (file)
index 0000000..4a8d599
--- /dev/null
@@ -0,0 +1,20 @@
+" Test for block inserting
+"
+" TODO: rewrite test39.in into this new style test
+
+func Test_blockinsert_indent()
+  new
+  filetype plugin indent on
+  setlocal sw=2 et ft=vim
+  call setline(1, ['let a=[', '  ''eins'',', '  ''zwei'',', '  ''drei'']'])
+  call cursor(2, 3)
+  exe "norm! \<c-v>2jI\\ \<esc>"
+  call assert_equal(['let a=[', '      \ ''eins'',', '      \ ''zwei'',', '      \ ''drei'']'],
+        \ getline(1,'$'))
+  " reset to sane state
+  filetype off
+  bwipe!
+endfunc
+
+
+" vim: shiftwidth=2 sts=2 expandtab
index d162de5e88f465cdb10064a1292ee9930cb46c0a..7cd61f35f267c89ace2551fb0550c62b7ba66a4d 100644 (file)
@@ -762,6 +762,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1682,
 /**/
     1681,
 /**/