diff options
author | glepnir <glephunter@gmail.com> | 2024-12-05 17:49:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-05 17:49:39 +0800 |
commit | 2f5e7cbac49ed2fde571c5bf85619afec624f8e8 (patch) | |
tree | 83a34f6938347bca119ec569e8d5602abd2a7711 /src/nvim/insexpand.c | |
parent | 540def7d2c1aa97d18b08bd7dc234442a7ab4757 (diff) | |
download | rneovim-2f5e7cbac49ed2fde571c5bf85619afec624f8e8.tar.gz rneovim-2f5e7cbac49ed2fde571c5bf85619afec624f8e8.tar.bz2 rneovim-2f5e7cbac49ed2fde571c5bf85619afec624f8e8.zip |
vim-patch:9.1.0905: Missing information in CompleteDone event (#31455)
Problem: Missing information in CompleteDone event
Solution: add complete_word and complete_type to v:event dict
(glepnir)
closes: vim/vim#16153
https://github.com/vim/vim/commit/1c5a120a701fcf558617c4e70b5a447778f0e51d
Diffstat (limited to 'src/nvim/insexpand.c')
-rw-r--r-- | src/nvim/insexpand.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index a1cebb407e..93d081153c 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -561,11 +561,19 @@ static bool is_first_match(const compl_T *const match) return match == compl_first_match; } -static void do_autocmd_completedone(int c) +static void do_autocmd_completedone(int c, int mode, char *word) { save_v_event_T save_v_event; dict_T *v_event = get_v_event(&save_v_event); + mode = mode & ~CTRL_X_WANT_IDENT; + char *mode_str = NULL; + if (ctrl_x_mode_names[mode]) { + mode_str = ctrl_x_mode_names[mode]; + } + 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_set_keys_readonly(v_event); @@ -2115,12 +2123,14 @@ static bool ins_compl_stop(const int c, const int prev_mode, bool retval) } } + char *word = NULL; // If the popup menu is displayed pressing CTRL-Y means accepting // the selection without inserting anything. When // compl_enter_selects is set the Enter key does the same. if ((c == Ctrl_Y || (compl_enter_selects && (c == CAR || c == K_KENTER || c == NL))) && pum_visible()) { + word = xstrdup(compl_shown_match->cp_str); retval = true; } @@ -2178,7 +2188,8 @@ static bool ins_compl_stop(const int c, const int prev_mode, bool retval) } // Trigger the CompleteDone event to give scripts a chance to act // upon the end of completion. - do_autocmd_completedone(c); + do_autocmd_completedone(c, prev_mode, word); + xfree(word); return retval; } @@ -2267,7 +2278,7 @@ bool ins_compl_prep(int c) } else if (ctrl_x_mode == CTRL_X_LOCAL_MSG) { // Trigger the CompleteDone event to give scripts a chance to act // upon the (possibly failed) completion. - do_autocmd_completedone(c); + do_autocmd_completedone(c, ctrl_x_mode, NULL); } may_trigger_modechanged(); |