diff --git a/doc/cmp.txt b/doc/cmp.txt index 9c05f32..5cc5f5e 100644 --- a/doc/cmp.txt +++ b/doc/cmp.txt @@ -209,6 +209,7 @@ NOTE: You can call these functions in mapping via `lua require('cmp').compl *cmp.event:on* ('%EVENT_NAME%, callback) Subscribe nvim-cmp's events below. + - `complete_done`: emit after current completion is done. - `confirm_done`: emit after confirmation is done. diff --git a/lua/cmp/core.lua b/lua/cmp/core.lua index 00bd2f0..4b72192 100644 --- a/lua/cmp/core.lua +++ b/lua/cmp/core.lua @@ -34,6 +34,9 @@ core.new = function() self.view.event:on('keymap', function(...) self:on_keymap(...) end) + self.view.event:on('complete_done', function(evt) + self.event:emit('complete_done', evt) + end) return self end @@ -425,7 +428,9 @@ core.confirm = function(self, e, option, callback) feedkeys.call('', 'n', function() e:execute(vim.schedule_wrap(function() release() - self.event:emit('confirm_done', e) + self.event:emit('confirm_done', { + entry = e + }) if callback then callback() end diff --git a/lua/cmp/init.lua b/lua/cmp/init.lua index aa8c81f..6212ab8 100644 --- a/lua/cmp/init.lua +++ b/lua/cmp/init.lua @@ -308,8 +308,16 @@ autocmd.subscribe('CursorMoved', function() end end) -cmp.event:on('confirm_done', function(e) - cmp.config.compare.recently_used:add_entry(e) +cmp.event:on('complete_done', function(evt) + if evt.entry then + cmp.config.compare.recently_used:add_entry(evt.entry) + end +end) + +cmp.event:on('confirm_done', function(evt) + if evt.entry then + cmp.config.compare.recently_used:add_entry(evt.entry) + end end) return cmp diff --git a/lua/cmp/view.lua b/lua/cmp/view.lua index 135ffa6..a786cce 100644 --- a/lua/cmp/view.lua +++ b/lua/cmp/view.lua @@ -109,8 +109,11 @@ view.open = function(self, ctx, sources) end end - -- close. + -- complete_done. if #entries == 0 then + self.event:emit('complete_done', { + entry = self:_get_entries_view():get_selected_entry() + }) self:close() end end