Skip to content

Commit 6180d65

Browse files
habamaxchrisbra
authored andcommitted
patch 9.1.1859: completion: whitespace not cleared with 'ai'
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 #18560 closes: #18582 Signed-off-by: Maxim Kim <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent b3b47e5 commit 6180d65

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/insexpand.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7115,7 +7115,10 @@ ins_compl_start(void)
71157115
can_si = FALSE;
71167116
can_si_back = FALSE;
71177117
if (stop_arrow() == FAIL)
7118+
{
7119+
did_ai = save_did_ai;
71187120
return FAIL;
7121+
}
71197122

71207123
line = ml_get(curwin->w_cursor.lnum);
71217124
curs_col = curwin->w_cursor.col;
@@ -7205,6 +7208,7 @@ ins_compl_start(void)
72057208
{
72067209
VIM_CLEAR_STRING(compl_pattern);
72077210
VIM_CLEAR_STRING(compl_orig_text);
7211+
did_ai = save_did_ai;
72087212
return FAIL;
72097213
}
72107214

@@ -7220,6 +7224,7 @@ ins_compl_start(void)
72207224
out_flush();
72217225
}
72227226

7227+
did_ai = save_did_ai;
72237228
return OK;
72247229
}
72257230

src/testdir/test_edit.vim

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,33 @@ func Test_autoindent_remove_indent()
458458
call delete('Xarifile')
459459
endfunc
460460

461+
" Test for autoindent removing indent when insert mode is stopped and
462+
" autocomplete is enabled. Some parts of the code is exercised only when
463+
" interactive mode is used. So use Vim in a terminal.
464+
func Test_autoindent_remove_indent_with_autocomplete()
465+
CheckRunVimInTerminal
466+
let buf = RunVimInTerminal('-N Xarifile', {'rows': 6, 'cols' : 20})
467+
call TermWait(buf)
468+
call term_sendkeys(buf, ":set autoindent autocomplete\n")
469+
" leaving insert mode in a new line with indent added by autoindent, should
470+
" remove the indent.
471+
call term_sendkeys(buf, "i\<Tab>foo\<CR>\<Esc>")
472+
" Need to delay for some time, otherwise the code in getchar.c will not be
473+
" exercised.
474+
call TermWait(buf, 50)
475+
" when a line is wrapped and the cursor is at the start of the second line,
476+
" leaving insert mode, should move the cursor back to the first line.
477+
call term_sendkeys(buf, "o" .. repeat('x', 20) .. "\<Esc>")
478+
" Need to delay for some time, otherwise the code in getchar.c will not be
479+
" exercised.
480+
call TermWait(buf, 50)
481+
call term_sendkeys(buf, ":w\n")
482+
call TermWait(buf)
483+
call StopVimInTerminal(buf)
484+
call assert_equal(["\tfoo", '', repeat('x', 20)], readfile('Xarifile'))
485+
call delete('Xarifile')
486+
endfunc
487+
461488
func Test_edit_esc_after_CR_autoindent()
462489
new
463490
setlocal autoindent

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
1859,
737739
/**/
738740
1858,
739741
/**/

0 commit comments

Comments
 (0)