diff --git a/src/insexpand.c b/src/insexpand.c index 214395f55e..4edcfe53e0 100644 --- a/src/insexpand.c +++ b/src/insexpand.c @@ -7115,7 +7115,10 @@ ins_compl_start(void) can_si = FALSE; can_si_back = FALSE; if (stop_arrow() == FAIL) + { + did_ai = save_did_ai; return FAIL; + } line = ml_get(curwin->w_cursor.lnum); curs_col = curwin->w_cursor.col; @@ -7205,6 +7208,7 @@ ins_compl_start(void) { VIM_CLEAR_STRING(compl_pattern); VIM_CLEAR_STRING(compl_orig_text); + did_ai = save_did_ai; return FAIL; } @@ -7220,6 +7224,7 @@ ins_compl_start(void) out_flush(); } + did_ai = save_did_ai; return OK; } diff --git a/src/testdir/test_edit.vim b/src/testdir/test_edit.vim index 7af4cdca6d..99e49661c1 100644 --- a/src/testdir/test_edit.vim +++ b/src/testdir/test_edit.vim @@ -458,6 +458,33 @@ func Test_autoindent_remove_indent() call delete('Xarifile') endfunc +" Test for autoindent removing indent when insert mode is stopped and +" autocomplete is enabled. Some parts of the code is exercised only when +" interactive mode is used. So use Vim in a terminal. +func Test_autoindent_remove_indent_with_autocomplete() + CheckRunVimInTerminal + let buf = RunVimInTerminal('-N Xarifile', {'rows': 6, 'cols' : 20}) + call TermWait(buf) + call term_sendkeys(buf, ":set autoindent autocomplete\n") + " leaving insert mode in a new line with indent added by autoindent, should + " remove the indent. + call term_sendkeys(buf, "i\foo\\") + " Need to delay for some time, otherwise the code in getchar.c will not be + " exercised. + call TermWait(buf, 50) + " when a line is wrapped and the cursor is at the start of the second line, + " leaving insert mode, should move the cursor back to the first line. + call term_sendkeys(buf, "o" .. repeat('x', 20) .. "\") + " Need to delay for some time, otherwise the code in getchar.c will not be + " exercised. + call TermWait(buf, 50) + call term_sendkeys(buf, ":w\n") + call TermWait(buf) + call StopVimInTerminal(buf) + call assert_equal(["\tfoo", '', repeat('x', 20)], readfile('Xarifile')) + call delete('Xarifile') +endfunc + func Test_edit_esc_after_CR_autoindent() new setlocal autoindent diff --git a/src/version.c b/src/version.c index 3217452c88..9288142506 100644 --- a/src/version.c +++ b/src/version.c @@ -734,6 +734,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1859, /**/ 1858, /**/