From 3a2f1bbc558a1f74adb69d6d26f19a7b85106a3b Mon Sep 17 00:00:00 2001 From: Daniel Fortes Date: Fri, 11 Feb 2022 02:11:00 -0300 Subject: [PATCH] Added `event_chars` property to `confirm_done event` (#782) * Added event_chars property to confirm_done event Currently it seems there is no way for someone listening to the `confirm_done` event to know exactly what character was used to commit the completion confirmation. This commit adds a `event_chars` property to the `confirm_done` event. Its value is just the `chars` variable form the `core.on_keymap` function. * Renamed `commid_chars` to `commit_character` --- lua/cmp/core.lua | 2 ++ lua/cmp/types/cmp.lua | 1 + 2 files changed, 3 insertions(+) diff --git a/lua/cmp/core.lua b/lua/cmp/core.lua index 36267a5..673a5cd 100644 --- a/lua/cmp/core.lua +++ b/lua/cmp/core.lua @@ -119,6 +119,7 @@ core.on_keymap = function(self, keys, fallback) local is_printable = char.is_printable(string.byte(chars, 1)) self:confirm(e, { behavior = is_printable and 'insert' or 'replace', + commit_character = chars, }, function() local ctx = self:get_context() local word = e:get_word() @@ -429,6 +430,7 @@ core.confirm = function(self, e, option, callback) release() self.event:emit('confirm_done', { entry = e, + commit_character = option.commit_character, }) if callback then callback() diff --git a/lua/cmp/types/cmp.lua b/lua/cmp/types/cmp.lua index 7d6b25f..df45d5e 100644 --- a/lua/cmp/types/cmp.lua +++ b/lua/cmp/types/cmp.lua @@ -38,6 +38,7 @@ cmp.ItemField.Menu = 'menu' ---@class cmp.ConfirmOption ---@field public behavior cmp.ConfirmBehavior +---@field public commit_character? string ---@class cmp.SelectOption ---@field public behavior cmp.SelectBehavior