diff options
-rw-r--r-- | runtime/doc/autocmd.txt | 10 | ||||
-rw-r--r-- | src/nvim/insexpand.c | 3 | ||||
-rw-r--r-- | test/functional/autocmd/completedone_spec.lua | 22 |
3 files changed, 22 insertions, 13 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 3ffbdf310f..eaa1b608ce 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -470,11 +470,11 @@ CompleteDone After Insert mode completion is done. Either reason Reason for completion being done. Can be one of: - "accept": completion was - accepted using |complete_CTRL-Y|. - - "cancel": completion was cancelled - using |complete_CTRL-E|, pressing - a non-keyword character, or - triggering a new completion. + accepted by |complete_CTRL-Y|. + - "cancel": completion was + stopped by |complete_CTRL-E. + - "discard": completion was + ended for other reason. *CursorHold* CursorHold When the user doesn't press a key for the time diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 4ed83312ef..fdae0d7327 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -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_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); ins_apply_autocmds(EVENT_COMPLETEDONE); diff --git a/test/functional/autocmd/completedone_spec.lua b/test/functional/autocmd/completedone_spec.lua index 36dc73842d..46c52cca8a 100644 --- a/test/functional/autocmd/completedone_spec.lua +++ b/test/functional/autocmd/completedone_spec.lua @@ -23,18 +23,26 @@ describe('CompleteDone', function() feed('<C-y>') eq('accept', eval('g:donereason')) end) - describe('cancel', function() - it('on <C-e>', function() - feed('<C-e>') - eq('cancel', eval('g:donereason')) - end) + + it('cancel', function() + feed('<C-e>') + eq('cancel', eval('g:donereason')) + end) + + describe('discard', function() it('on non-keyword character', function() + feed('<Space>') + eq('discard', eval('g:donereason')) + end) + + it('on mode change', function() feed('<Esc>') - eq('cancel', eval('g:donereason')) + eq('discard', eval('g:donereason')) end) + it('when overridden by another complete()', function() call('complete', call('col', '.'), { 'bar', 'baz' }) - eq('cancel', eval('g:donereason')) + eq('discard', eval('g:donereason')) end) end) end) |