Wait for filtering completion
This commit is contained in:
@@ -175,7 +175,9 @@ cmp.confirm = function(option, callback)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
cmp.core.filter.raw(cmp.core)
|
vim.wait(1000, function()
|
||||||
|
return not cmp.core.filter.running
|
||||||
|
end)
|
||||||
local e = cmp.core.view:get_selected_entry() or (option.select and cmp.core.view:get_first_entry() or nil)
|
local e = cmp.core.view:get_selected_entry() or (option.select and cmp.core.view:get_first_entry() or nil)
|
||||||
if e then
|
if e then
|
||||||
cmp.core:confirm(e, {
|
cmp.core:confirm(e, {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
local async = {}
|
local async = {}
|
||||||
|
|
||||||
---@class cmp.AsyncThrottle
|
---@class cmp.AsyncThrottle
|
||||||
|
---@field public running boolean
|
||||||
---@field public timeout number
|
---@field public timeout number
|
||||||
---@field public stop function
|
---@field public stop function
|
||||||
---@field public raw function
|
|
||||||
---@field public __call function
|
---@field public __call function
|
||||||
|
|
||||||
---@param fn function
|
---@param fn function
|
||||||
@@ -18,10 +18,7 @@ async.throttle = function(fn, timeout)
|
|||||||
stop = function()
|
stop = function()
|
||||||
time = nil
|
time = nil
|
||||||
timer:stop()
|
timer:stop()
|
||||||
end,
|
end
|
||||||
raw = function(...)
|
|
||||||
fn(...)
|
|
||||||
end,
|
|
||||||
}, {
|
}, {
|
||||||
__call = function(self, ...)
|
__call = function(self, ...)
|
||||||
local args = { ... }
|
local args = { ... }
|
||||||
@@ -29,18 +26,15 @@ async.throttle = function(fn, timeout)
|
|||||||
if time == nil then
|
if time == nil then
|
||||||
time = vim.loop.now()
|
time = vim.loop.now()
|
||||||
end
|
end
|
||||||
timer:stop()
|
|
||||||
|
|
||||||
local delta = math.max(1, self.timeout - (vim.loop.now() - time))
|
self.running = true
|
||||||
timer:start(delta, 0, function()
|
timer:stop()
|
||||||
if not self.running then
|
timer:start(math.max(1, self.timeout - (vim.loop.now() - time)), 0, function()
|
||||||
|
vim.schedule(function()
|
||||||
time = nil
|
time = nil
|
||||||
self.running = true
|
self.running = false
|
||||||
vim.schedule(function()
|
fn(unpack(args))
|
||||||
self.running = false
|
end)
|
||||||
fn(unpack(args))
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user