diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index f5799ddfa9..8a1f80776d 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -6054,6 +6054,7 @@ static int ins_compl_start(void) can_si = false; can_si_back = false; if (stop_arrow() == FAIL) { + did_ai = save_did_ai; return FAIL; } @@ -6148,6 +6149,7 @@ static int ins_compl_start(void) API_CLEAR_STRING(compl_pattern); API_CLEAR_STRING(compl_orig_text); kv_destroy(compl_orig_extmarks); + did_ai = save_did_ai; return FAIL; } @@ -6162,6 +6164,7 @@ static int ins_compl_start(void) ui_flush(); } + did_ai = save_did_ai; return OK; } diff --git a/test/old/testdir/test_edit.vim b/test/old/testdir/test_edit.vim index 4cc529702b..59517726f0 100644 --- a/test/old/testdir/test_edit.vim +++ b/test/old/testdir/test_edit.vim @@ -466,6 +466,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