From e2166661d483c283f48aafc2fa5fde08b07f8594 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 19 Sep 2025 10:47:53 +0800 Subject: [PATCH] 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 https://github.com/vim/vim/commit/86e8e909f2e8cc1f851b4b62c3060c86c1afae65 Co-authored-by: Girish Palya --- src/nvim/insexpand.c | 2 +- test/functional/editor/completion_spec.lua | 46 +++++++++++++++++++++- test/old/testdir/test_ins_complete.vim | 23 +++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index ad00d12b3c..eff661dc6d 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -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; } } diff --git a/test/functional/editor/completion_spec.lua b/test/functional/editor/completion_spec.lua index 4c11c1a661..453b0c483e 100644 --- a/test/functional/editor/completion_spec.lua +++ b/test/functional/editor/completion_spec.lua @@ -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('') 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('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) diff --git a/test/old/testdir/test_ins_complete.vim b/test/old/testdir/test_ins_complete.vim index 12ccf00a7d..d08ba57513 100644 --- a/test/old/testdir/test_ins_complete.vim +++ b/test/old/testdir/test_ins_complete.vim @@ -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, "\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, "\") + call StopVimInTerminal(buf) +endfunc + " vim: shiftwidth=2 sts=2 expandtab nofoldenable