mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
feat(complete): CompleteDone reason "cancel", "discard" #32600
Problem: there is no way to distinguish between user's explicit completion stop/cancel and other automated reasons. Solution: update "cancel" reason to be set only on explicit CTRL-e, and set intentionally vague "discard" otherwise.
This commit is contained in:

committed by
GitHub

parent
07c5f41da3
commit
268a3de0a7
@@ -470,11 +470,11 @@ CompleteDone After Insert mode completion is done. Either
|
|||||||
reason Reason for completion being
|
reason Reason for completion being
|
||||||
done. Can be one of:
|
done. Can be one of:
|
||||||
- "accept": completion was
|
- "accept": completion was
|
||||||
accepted using |complete_CTRL-Y|.
|
accepted by |complete_CTRL-Y|.
|
||||||
- "cancel": completion was cancelled
|
- "cancel": completion was
|
||||||
using |complete_CTRL-E|, pressing
|
stopped by |complete_CTRL-E.
|
||||||
a non-keyword character, or
|
- "discard": completion was
|
||||||
triggering a new completion.
|
ended for other reason.
|
||||||
|
|
||||||
*CursorHold*
|
*CursorHold*
|
||||||
CursorHold When the user doesn't press a key for the time
|
CursorHold When the user doesn't press a key for the time
|
||||||
|
@@ -581,7 +581,8 @@ static void do_autocmd_completedone(int c, int mode, char *word)
|
|||||||
tv_dict_add_str(v_event, S_LEN("complete_word"), word != NULL ? word : "");
|
tv_dict_add_str(v_event, S_LEN("complete_word"), word != NULL ? 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"), (c == Ctrl_Y ? "accept" : "cancel"));
|
tv_dict_add_str(v_event, S_LEN("reason"),
|
||||||
|
(c == Ctrl_Y ? "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);
|
||||||
|
@@ -23,18 +23,26 @@ describe('CompleteDone', function()
|
|||||||
feed('<C-y>')
|
feed('<C-y>')
|
||||||
eq('accept', eval('g:donereason'))
|
eq('accept', eval('g:donereason'))
|
||||||
end)
|
end)
|
||||||
describe('cancel', function()
|
|
||||||
it('on <C-e>', function()
|
it('cancel', function()
|
||||||
feed('<C-e>')
|
feed('<C-e>')
|
||||||
eq('cancel', eval('g:donereason'))
|
eq('cancel', eval('g:donereason'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('discard', function()
|
||||||
it('on non-keyword character', function()
|
it('on non-keyword character', function()
|
||||||
feed('<Esc>')
|
feed('<Space>')
|
||||||
eq('cancel', eval('g:donereason'))
|
eq('discard', eval('g:donereason'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('on mode change', function()
|
||||||
|
feed('<Esc>')
|
||||||
|
eq('discard', eval('g:donereason'))
|
||||||
|
end)
|
||||||
|
|
||||||
it('when overridden by another complete()', function()
|
it('when overridden by another complete()', function()
|
||||||
call('complete', call('col', '.'), { 'bar', 'baz' })
|
call('complete', call('col', '.'), { 'bar', 'baz' })
|
||||||
eq('cancel', eval('g:donereason'))
|
eq('discard', eval('g:donereason'))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user