From e55033fce468c9c578b946948807f2ac48a6ee08 Mon Sep 17 00:00:00 2001 From: hrsh7th <629908+hrsh7th@users.noreply.github.com> Date: Tue, 27 Dec 2022 15:53:05 +0900 Subject: [PATCH] Fix #1322 --- lua/cmp/init.lua | 3 ++- lua/cmp/utils/async.lua | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lua/cmp/init.lua b/lua/cmp/init.lua index 44d49bc..03722b6 100644 --- a/lua/cmp/init.lua +++ b/lua/cmp/init.lua @@ -304,7 +304,8 @@ local on_insert_enter = function() cmp.core:on_change('InsertEnter') end end -autocmd.subscribe({ 'InsertEnter', 'CmdlineEnter' }, async.debounce_next_tick(on_insert_enter)) +autocmd.subscribe({ 'CmdlineEnter' }, async.debounce_next_tick(on_insert_enter)) +autocmd.subscribe({ 'InsertEnter' }, async.debounce_next_tick_by_keymap(on_insert_enter)) -- async.throttle is needed for performance. The mapping `:...` will fire `CmdlineChanged` for each character. local on_text_changed = function() diff --git a/lua/cmp/utils/async.lua b/lua/cmp/utils/async.lua index 8822112..fdfc7aa 100644 --- a/lua/cmp/utils/async.lua +++ b/lua/cmp/utils/async.lua @@ -1,3 +1,5 @@ +local feedkeys = require('cmp.utils.feedkeys') + local async = {} ---@class cmp.AsyncThrottle @@ -138,4 +140,11 @@ async.debounce_next_tick = function(callback) end end +---Wait and callback for consuming next keymap. +async.debounce_next_tick_by_keymap = function(callback) + return function() + feedkeys.call('', '', callback) + end +end + return async