vim-patch:9.1.1772: completion: inconsistent selection of first item with 'autocomplete' (#35835)

Problem:  completion: inconsistent selection of first item with
          'autocomplete' (Tomasz N)
Solution: Check for 'autocomplete' option in ins_compl_new_leader()
          (Girish Palya).

fixes: vim/vim#18326
closes: vim/vim#18329

86e8e909f2

Co-authored-by: Girish Palya <girishji@gmail.com>
This commit is contained in:
zeertzjq
2025-09-19 10:47:53 +08:00
committed by GitHub
parent 95267b664c
commit e2166661d4
3 changed files with 69 additions and 2 deletions

View File

@@ -2274,7 +2274,7 @@ static void ins_compl_new_leader(void)
if ((cur_cot_flags & (kOptCotFlagNoinsert|kOptCotFlagNoselect)) == kOptCotFlagNoinsert
&& compl_first_match) {
compl_shown_match = compl_first_match;
if (compl_shows_dir_forward()) {
if (compl_shows_dir_forward() && !compl_autocomplete) {
compl_shown_match = compl_first_match->cp_next;
}
}

View File

@@ -1413,11 +1413,11 @@ describe('completion', function()
-- oldtest: Test_autocompletedelay()
it("'autocompletedelay' option", function()
screen:try_resize(60, 10)
source([[
call setline(1, ['foo', 'foobar', 'foobarbaz'])
set autocomplete
]])
screen:try_resize(60, 10)
screen:expect([[
^foo |
foobar |
@@ -1579,4 +1579,48 @@ describe('completion', function()
feed('<esc>')
end)
it([[first item isn't selected with "fuzzy" and 'acl']], function()
screen:try_resize(60, 10)
source([[
call setline(1, ["v", "vi", "vim"])
set autocomplete completeopt=menuone,noinsert,fuzzy autocompletedelay=300
]])
feed('Govi')
screen:expect([[
v |
vi |
vim |
vi^ |
{4:vi }{1: }|
{4:vim }{1: }|
{1:~ }|*3
{5:-- INSERT --} |
]])
feed('<Esc>Sv')
screen:expect([[
v |
vi |
vim |
v^ |
{4:v }{1: }|
{4:vi }{1: }|
{4:vim }{1: }|
{1:~ }|*2
{5:-- INSERT --} |
]])
feed('i')
screen:expect([[
v |
vi |
vim |
vi^ |
{4:vi }{1: }|
{4:vim }{1: }|
{1:~ }|*3
{5:-- INSERT --} |
]])
end)
end)

View File

@@ -5842,4 +5842,27 @@ func Test_autocomplete_completeopt_preinsert()
call Ntest_override("char_avail", 0)
endfunc
" Issue #18326
func Test_fuzzy_select_item_when_acl()
CheckScreendump
let lines =<< trim [SCRIPT]
call setline(1, ["v", "vi", "vim"])
set autocomplete completeopt=menuone,noinsert,fuzzy autocompletedelay=300
[SCRIPT]
call writefile(lines, 'XTest_autocomplete_delay', 'D')
let buf = RunVimInTerminal('-S XTest_autocomplete_delay', {'rows': 10})
call term_sendkeys(buf, "Govi")
call VerifyScreenDump(buf, 'Test_fuzzy_autocompletedelay_1', {})
call term_sendkeys(buf, "\<Esc>Sv")
call VerifyScreenDump(buf, 'Test_fuzzy_autocompletedelay_2', {})
sleep 500m
call term_sendkeys(buf, "i")
call VerifyScreenDump(buf, 'Test_fuzzy_autocompletedelay_3', {})
call term_sendkeys(buf, "\<esc>")
call StopVimInTerminal(buf)
endfunc
" vim: shiftwidth=2 sts=2 expandtab nofoldenable