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

6180d65751

Co-authored-by: Maxim Kim <habamax@gmail.com>
This commit is contained in:
zeertzjq
2025-10-17 10:51:49 +08:00
committed by GitHub
parent 550033d51d
commit a08aa77e40
2 changed files with 30 additions and 0 deletions

View File

@@ -6054,6 +6054,7 @@ static int ins_compl_start(void)
can_si = false; can_si = false;
can_si_back = false; can_si_back = false;
if (stop_arrow() == FAIL) { if (stop_arrow() == FAIL) {
did_ai = save_did_ai;
return FAIL; return FAIL;
} }
@@ -6148,6 +6149,7 @@ static int ins_compl_start(void)
API_CLEAR_STRING(compl_pattern); API_CLEAR_STRING(compl_pattern);
API_CLEAR_STRING(compl_orig_text); API_CLEAR_STRING(compl_orig_text);
kv_destroy(compl_orig_extmarks); kv_destroy(compl_orig_extmarks);
did_ai = save_did_ai;
return FAIL; return FAIL;
} }
@@ -6162,6 +6164,7 @@ static int ins_compl_start(void)
ui_flush(); ui_flush();
} }
did_ai = save_did_ai;
return OK; return OK;
} }

View File

@@ -466,6 +466,33 @@ func Test_autoindent_remove_indent()
call delete('Xarifile') call delete('Xarifile')
endfunc 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\<Tab>foo\<CR>\<Esc>")
" 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) .. "\<Esc>")
" 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() func Test_edit_esc_after_CR_autoindent()
new new
setlocal autoindent setlocal autoindent