vim-patch:9.1.1820: completion: some issues with 'acl' (#36007)

Problem:  completion: some issues with 'acl' when "preinsert" and
          "longest" is in 'completeopt' (musonius, after v9.1.1638)
Solution: Fix various issues (see details below) (Girish Palya)

This commit addresses multiple issues in the 'autocompletedelay' behavior with
"preinsert" and "longest":

- Prevents spurious characters from being inserted.
- Ensures the completion menu is not shown until `autocompletedelay` has
  expired.
- Shows the "preinsert" effect immediately.
- Keeps the "preinsert" effect visible even when a character is deleted.

fixes: vim/vim#18443
closes: vim/vim#18460

f77c187277

Co-authored-by: Girish Palya <girishji@gmail.com>
This commit is contained in:
zeertzjq
2025-10-03 21:10:05 +08:00
committed by GitHub
parent 97ab7dd784
commit 8151fc59cf
3 changed files with 150 additions and 4 deletions

View File

@@ -1591,6 +1591,7 @@ describe('completion', function()
feed('<esc>')
end)
-- oldtest: Test_fuzzy_select_item_when_acl()
it([[first item isn't selected with "fuzzy" and 'acl']], function()
screen:try_resize(60, 10)
source([[
@@ -1634,4 +1635,98 @@ describe('completion', function()
{5:-- INSERT --} |
]])
end)
-- oldtest: Test_autocompletedelay_longest_preinsert()
it("'autocompletedelay' with 'completeopt' longest/preinsert", function()
source([[
call setline(1, ['autocomplete', 'autocomxxx'])
set autocomplete completeopt+=longest autocompletedelay=500
]])
screen:expect([[
^autocomplete |
autocomxxx |
{1:~ }|*5
|
]])
screen.timeout = 400
-- No spurious characters when autocompletedelay is in effect
feed('Goau')
screen:expect([[
autocomplete |
autocomxxx |
au{102:^tocom} |
{1:~ }|*4
{5:-- INSERT --} |
]])
feed('toc')
screen:expect([[
autocomplete |
autocomxxx |
autoc{102:^om} |
{1:~ }|*4
{5:-- INSERT --} |
]])
vim.uv.sleep(500)
screen:expect([[
autocomplete |
autocomxxx |
autoc{102:^om} |
{4:autocomxxx }{1: }|
{4:autocomplete }{1: }|
{1:~ }|*2
{5:-- INSERT --} |
]])
-- Deleting a char should still show longest text
feed('<Esc>Saut')
screen:expect([[
autocomplete |
autocomxxx |
aut{102:^ocom} |
{1:~ }|*4
{5:-- INSERT --} |
]])
feed('<BS>')
screen:expect([[
autocomplete |
autocomxxx |
au{102:^tocom} |
{1:~ }|*4
{5:-- INSERT --} |
]])
vim.uv.sleep(500)
screen:expect([[
autocomplete |
autocomxxx |
au{102:^tocom} |
{4:autocomxxx }{1: }|
{4:autocomplete }{1: }|
{1:~ }|*2
{5:-- INSERT --} |
]])
-- Preinsert
command('set completeopt& completeopt+=preinsert')
-- Show preinserted text right away but display popup later
feed('<Esc>Sau')
screen:expect([[
autocomplete |
autocomxxx |
au{102:^tocomplete} |
{1:~ }|*4
{5:-- INSERT --} |
]])
vim.uv.sleep(500)
screen:expect([[
autocomplete |
autocomxxx |
au{102:^tocomplete} |
{12:autocomplete }{1: }|
{4:autocomxxx }{1: }|
{1:~ }|*2
{5:-- INSERT --} |
]])
end)
end)

View File

@@ -5869,7 +5869,7 @@ func Test_autocomplete_longest()
call Ntest_override("char_avail", 1)
new
inoremap <buffer><F5> <C-R>=GetLine()<CR>
set completeopt=longest autocomplete
set completeopt+=longest autocomplete
call setline(1, ["foobar", "foozbar"])
call feedkeys("Go\<ESC>", 'tx')
@@ -6109,4 +6109,45 @@ func Test_refresh_always_with_fuzzy()
call Ntest_override("char_avail", 0)
endfunc
func Test_autocompletedelay_longest_preinsert()
CheckScreendump
let lines =<< trim [SCRIPT]
call setline(1, ['autocomplete', 'autocomxxx'])
set autocomplete completeopt+=longest autocompletedelay=500
[SCRIPT]
call writefile(lines, 'XTest_autocompletedelay', 'D')
let buf = RunVimInTerminal('-S XTest_autocompletedelay', {'rows': 10})
" No spurious characters when autocompletedelay is in effect
call term_sendkeys(buf, "Goau")
sleep 10m
call term_sendkeys(buf, "toc")
sleep 100m
call VerifyScreenDump(buf, 'Test_autocompletedelay_longest_1', {})
sleep 500m
call VerifyScreenDump(buf, 'Test_autocompletedelay_longest_2', {})
" Deleting a char should still show longest text
call term_sendkeys(buf, "\<Esc>Saut")
sleep 10m
call term_sendkeys(buf, "\<BS>")
sleep 100m
call VerifyScreenDump(buf, 'Test_autocompletedelay_longest_3', {})
sleep 500m
call VerifyScreenDump(buf, 'Test_autocompletedelay_longest_4', {})
" Preinsert
call term_sendkeys(buf, "\<Esc>:set completeopt& completeopt+=preinsert\<CR>")
" Show preinserted text right away but display popup later
call term_sendkeys(buf, "\<Esc>Sau")
sleep 100m
call VerifyScreenDump(buf, 'Test_autocompletedelay_preinsert_1', {})
sleep 500m
call VerifyScreenDump(buf, 'Test_autocompletedelay_preinsert_2', {})
call term_sendkeys(buf, "\<esc>")
call StopVimInTerminal(buf)
endfunc
" vim: shiftwidth=2 sts=2 expandtab nofoldenable