]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1859: completion: whitespace not cleared with 'ai' v9.1.1859
authorMaxim Kim <habamax@gmail.com>
Thu, 16 Oct 2025 18:32:21 +0000 (18:32 +0000)
committerChristian Brabandt <cb@256bit.org>
Thu, 16 Oct 2025 18:32:21 +0000 (18:32 +0000)
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 <habamax@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/insexpand.c
src/testdir/test_edit.vim
src/version.c

index 214395f55e18ed6cecd958dc7f9c065672e1c39b..4edcfe53e043024fd79621b03c105766b7142767 100644 (file)
@@ -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;
 }
 
index 7af4cdca6d6422929ddb10cc43fcf05123931e1f..99e49661c117ce215e83ec68081da36ad31516b5 100644 (file)
@@ -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\<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()
   new
   setlocal autoindent
index 3217452c88ece40b0e3f7d22e7b7a8456b009300..9288142506a2c988962610a530e314c33ca9cedb 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1859,
 /**/
     1858,
 /**/