diff --git a/lua/cmp/utils/misc.lua b/lua/cmp/utils/misc.lua index a70d0b1..5f4f81d 100644 --- a/lua/cmp/utils/misc.lua +++ b/lua/cmp/utils/misc.lua @@ -180,4 +180,27 @@ misc.deprecated = function(fn, msg) end end +--Redraw +misc.redraw = setmetatable({ + doing = false, + force = false, +}, { + __call = function(self, force) + if self.doing then + return + end + self.doing = true + self.force = not not force + vim.schedule(function() + if self.force then + vim.cmd([[redraw!]]) + else + vim.cmd([[redraw]]) + end + self.doing = false + self.force = false + end) + end +}) + return misc diff --git a/lua/cmp/utils/window.lua b/lua/cmp/utils/window.lua index fb083b6..8e2bf02 100644 --- a/lua/cmp/utils/window.lua +++ b/lua/cmp/utils/window.lua @@ -176,7 +176,7 @@ window.update = function(self) -- In cmdline, vim does not redraw automatically. if api.is_cmdline_mode() then vim.api.nvim_win_call(self.win, function() - vim.cmd([[redraw]]) + misc.redraw() end) end end diff --git a/lua/cmp/view/custom_entries_view.lua b/lua/cmp/view/custom_entries_view.lua index 016633a..d84baee 100644 --- a/lua/cmp/view/custom_entries_view.lua +++ b/lua/cmp/view/custom_entries_view.lua @@ -5,6 +5,7 @@ local window = require('cmp.utils.window') local config = require('cmp.config') local types = require('cmp.types') local keymap = require('cmp.utils.keymap') +local misc = require('cmp.utils.misc') local api = require('cmp.utils.api') local SIDE_PADDING = 1 @@ -221,7 +222,7 @@ custom_entries_view.draw = function(self) if api.is_cmdline_mode() then vim.api.nvim_win_call(self.entries_win.win, function() - vim.cmd([[redraw]]) + misc.redraw() end) end end diff --git a/lua/cmp/view/ghost_text_view.lua b/lua/cmp/view/ghost_text_view.lua index 786288e..b798ebb 100644 --- a/lua/cmp/view/ghost_text_view.lua +++ b/lua/cmp/view/ghost_text_view.lua @@ -1,4 +1,5 @@ local config = require('cmp.config') +local misc = require('cmp.utils.misc') local str = require('cmp.utils.str') local types = require('cmp.types') local api = require('cmp.utils.api') @@ -81,7 +82,7 @@ ghost_text_view.show = function(self, e) self.win = vim.api.nvim_get_current_win() self.entry = e if changed then - vim.cmd([[redraw!]]) -- force invoke decoration provider. + misc.redraw(true) -- force invoke decoration provider. end end @@ -89,7 +90,7 @@ ghost_text_view.hide = function(self) if self.win and self.entry then self.win = nil self.entry = nil - vim.cmd([[redraw!]]) -- force invoke decoration provider. + misc.redraw(true) -- force invoke decoration provider. end end