mirror of
https://github.com/neovim/neovim.git
synced 2026-05-01 19:45:02 +00:00
fix(completion): CompleteDone reason="discard" when candidate text remains #38169
Problem: CompleteDone fires with reason="discard" even when the candidate text was inserted and left in the buffer, because reason was determined solely by the terminating keycode (Ctrl-Y). Solution: Check compl_used_match to detect whether inserted text remains in the buffer, and set reason="accept" accordingly.
This commit is contained in:
@@ -650,7 +650,7 @@ static void do_autocmd_completedone(int c, int mode, char *word)
|
|||||||
tv_dict_add_str(v_event, S_LEN("complete_type"), mode_str != NULL ? mode_str : "");
|
tv_dict_add_str(v_event, S_LEN("complete_type"), mode_str != NULL ? mode_str : "");
|
||||||
|
|
||||||
tv_dict_add_str(v_event, S_LEN("reason"),
|
tv_dict_add_str(v_event, S_LEN("reason"),
|
||||||
(c == Ctrl_Y ? "accept" : (c == Ctrl_E ? "cancel" : "discard")));
|
(compl_used_match ? "accept" : (c == Ctrl_E ? "cancel" : "discard")));
|
||||||
tv_dict_set_keys_readonly(v_event);
|
tv_dict_set_keys_readonly(v_event);
|
||||||
|
|
||||||
ins_apply_autocmds(EVENT_COMPLETEDONE);
|
ins_apply_autocmds(EVENT_COMPLETEDONE);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ describe('CompleteDone', function()
|
|||||||
|
|
||||||
describe('sets v:event.reason', function()
|
describe('sets v:event.reason', function()
|
||||||
before_each(function()
|
before_each(function()
|
||||||
|
command('set completeopt+=noinsert')
|
||||||
command('autocmd CompleteDone * let g:donereason = v:event.reason')
|
command('autocmd CompleteDone * let g:donereason = v:event.reason')
|
||||||
feed('i')
|
feed('i')
|
||||||
call('complete', call('col', '.'), { 'foo', 'bar' })
|
call('complete', call('col', '.'), { 'foo', 'bar' })
|
||||||
@@ -23,6 +24,19 @@ describe('CompleteDone', function()
|
|||||||
eq('accept', eval('g:donereason'))
|
eq('accept', eval('g:donereason'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('accept when candidate is inserted without noinsert #38160', function()
|
||||||
|
command('set completeopt=menu,menuone') -- Omit "noinsert".
|
||||||
|
feed('<ESC>Stest<CR><C-N><ESC>')
|
||||||
|
eq('accept', eval('g:donereason'))
|
||||||
|
eq('test', n.api.nvim_get_current_line())
|
||||||
|
feed('Stip<CR>t<C-N><C-N><ESC>')
|
||||||
|
eq('accept', eval('g:donereason'))
|
||||||
|
eq('tip', n.api.nvim_get_current_line())
|
||||||
|
feed('Stry<CR>t<C-N><C-N><C-N><Space>')
|
||||||
|
eq('accept', eval('g:donereason'))
|
||||||
|
eq('try ', n.api.nvim_get_current_line())
|
||||||
|
end)
|
||||||
|
|
||||||
it('cancel', function()
|
it('cancel', function()
|
||||||
feed('<C-e>')
|
feed('<C-e>')
|
||||||
eq('cancel', eval('g:donereason'))
|
eq('cancel', eval('g:donereason'))
|
||||||
|
|||||||
Reference in New Issue
Block a user