From a226b6a4ff72e5e809ed17734318233fb25c87f3 Mon Sep 17 00:00:00 2001 From: hrsh7th <> Date: Mon, 9 May 2022 11:55:29 +0900 Subject: [PATCH] Fix #973 --- lua/cmp/init.lua | 52 +++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/lua/cmp/init.lua b/lua/cmp/init.lua index c27acca..60184d0 100644 --- a/lua/cmp/init.lua +++ b/lua/cmp/init.lua @@ -285,39 +285,33 @@ cmp.setup = setmetatable({ }) -- In InsertEnter autocmd, vim will detects mode=normal unexpectedly. -autocmd.subscribe( - { 'InsertEnter', 'CmdlineEnter' }, - async.debounce_next_tick(function() - if config.enabled() then - cmp.config.compare.scopes:update() - cmp.config.compare.locality:update() - cmp.core:prepare() - cmp.core:on_change('InsertEnter') - end - end) -) +local on_insert_enter = function() + if config.enabled() then + cmp.config.compare.scopes:update() + cmp.config.compare.locality:update() + cmp.core:prepare() + cmp.core:on_change('InsertEnter') + end +end +autocmd.subscribe({ 'InsertEnter', 'CmdlineEnter' }, async.debounce_next_tick(on_insert_enter)) -- async.throttle is needed for performance. The mapping `:...` will fire `CmdlineChanged` for each character. -autocmd.subscribe( - { 'TextChangedI', 'TextChangedP', 'CmdlineChanged' }, - async.debounce_next_tick(function() - if config.enabled() then - cmp.core:on_change('TextChanged') - end - end) -) +local on_text_changed = function() + if config.enabled() then + cmp.core:on_change('TextChanged') + end +end +autocmd.subscribe({ 'TextChangedI', 'TextChangedP' }, on_text_changed) +autocmd.subscribe('CmdlineChanged', async.debounce_next_tick(on_text_changed)) -autocmd.subscribe( - 'CursorMovedI', - async.debounce_next_tick(function() - if config.enabled() then - cmp.core:on_moved() +autocmd.subscribe('CursorMovedI', function() + if config.enabled() then + cmp.core:on_moved() else - cmp.core:reset() - cmp.core.view:close() - end - end) -) + cmp.core:reset() + cmp.core.view:close() + end +end) -- If make this asynchronous, the completion menu will not close when the command output is displayed. autocmd.subscribe({ 'InsertLeave', 'CmdlineLeave' }, function()