From a08aa77e4084e2b380f23b7a10f41eb20371d6c3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 17 Oct 2025 10:51:49 +0800 Subject: [PATCH] vim-patch:9.1.1859: completion: whitespace not cleared with 'ai' (#36218) Problem: completion: whitespace not cleared with 'ai' Solution: Remove spaces added by 'autoindent' when autocomplete is set and restore did_ai in ins_compl_start() (Maxim Kim) fixes vim/vim#18560 closes: vim/vim#18582 https://github.com/vim/vim/commit/6180d65751d8cc85460eb1729dd04815b9f14aa4 Co-authored-by: Maxim Kim --- src/nvim/insexpand.c | 3 +++ test/old/testdir/test_edit.vim | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) 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