Skip to content

Commit 8c87a2b

Browse files
committed
patch 8.0.1682: auto indenting breaks inserting a block
Problem: Auto indenting breaks inserting a block. Solution: Do not check for cursor movement if indent was changed. (Christian Brabandt, closes #2778)
1 parent e80757c commit 8c87a2b

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

src/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -2127,6 +2127,7 @@ test_arglist \
21272127
test_autocmd \
21282128
test_autoload \
21292129
test_backspace_opt \
2130+
test_blockedit \
21302131
test_breakindent \
21312132
test_bufline \
21322133
test_bufwintabinfo \

src/ops.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ do_record(int c)
10931093

10941094
if (Recording == FALSE) /* start recording */
10951095
{
1096-
/* registers 0-9, a-z and " are allowed */
1096+
/* registers 0-9, a-z and " are allowed */
10971097
if (c < 0 || (!ASCII_ISALNUM(c) && c != '"'))
10981098
retval = FAIL;
10991099
else
@@ -2702,6 +2702,7 @@ op_insert(oparg_T *oap, long count1)
27022702
if (oap->block_mode)
27032703
{
27042704
struct block_def bd2;
2705+
int did_indent = FALSE;
27052706

27062707
/* If indent kicked in, the firstline might have changed
27072708
* but only do that, if the indent actually increased. */
@@ -2710,11 +2711,14 @@ op_insert(oparg_T *oap, long count1)
27102711
{
27112712
bd.textcol += ind_post - ind_pre;
27122713
bd.start_vcol += ind_post - ind_pre;
2714+
did_indent = TRUE;
27132715
}
27142716

27152717
/* The user may have moved the cursor before inserting something, try
2716-
* to adjust the block for that. */
2717-
if (oap->start.lnum == curbuf->b_op_start_orig.lnum && !bd.is_MAX)
2718+
* to adjust the block for that. But only do it, if the difference
2719+
* does not come from indent kicking in. */
2720+
if (oap->start.lnum == curbuf->b_op_start_orig.lnum
2721+
&& !bd.is_MAX && !did_indent)
27182722
{
27192723
if (oap->op_type == OP_INSERT
27202724
&& oap->start.col

src/testdir/Make_all.mak

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ NEW_TESTS = test_arabic.res \
7272
test_autocmd.res \
7373
test_autoload.res \
7474
test_backspace_opt.res \
75+
test_blockedit.res \
7576
test_breakindent.res \
7677
test_bufwintabinfo.res \
7778
test_cdo.res \

src/testdir/test_blockedit.vim

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
" Test for block inserting
2+
"
3+
" TODO: rewrite test39.in into this new style test
4+
5+
func Test_blockinsert_indent()
6+
new
7+
filetype plugin indent on
8+
setlocal sw=2 et ft=vim
9+
call setline(1, ['let a=[', ' ''eins'',', ' ''zwei'',', ' ''drei'']'])
10+
call cursor(2, 3)
11+
exe "norm! \<c-v>2jI\\ \<esc>"
12+
call assert_equal(['let a=[', ' \ ''eins'',', ' \ ''zwei'',', ' \ ''drei'']'],
13+
\ getline(1,'$'))
14+
" reset to sane state
15+
filetype off
16+
bwipe!
17+
endfunc
18+
19+
20+
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

+2
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,8 @@ static char *(features[]) =
762762

763763
static int included_patches[] =
764764
{ /* Add new patch number below this line */
765+
/**/
766+
1682,
765767
/**/
766768
1681,
767769
/**/

0 commit comments

Comments
 (0)