fix: only schedule_wrap when necessary (#58)

This commit is contained in:
Steven Arcangeli 2022-08-28 10:18:01 -07:00
parent be2ef16ddb
commit 232b6b3021
3 changed files with 13 additions and 2 deletions

View File

@ -273,7 +273,7 @@ end
setmetatable(M, {
-- use schedule_wrap to avoid a bug when vim opens
-- (see https://github.com/stevearc/dressing.nvim/issues/15)
__call = vim.schedule_wrap(function(_, opts, on_confirm)
__call = util.schedule_wrap_before_vimenter(function(_, opts, on_confirm)
vim.validate({
on_confirm = { on_confirm, "function", false },
})

View File

@ -1,5 +1,6 @@
local global_config = require("dressing.config")
local patch = require("dressing.patch")
local util = require("dressing.util")
local function get_backend(config)
local backends = config.backend
@ -17,7 +18,7 @@ end
-- use schedule_wrap to avoid a bug when vim opens
-- (see https://github.com/stevearc/dressing.nvim/issues/15)
return vim.schedule_wrap(function(items, opts, on_choice)
return util.schedule_wrap_before_vimenter(function(items, opts, on_choice)
vim.validate({
items = {
items,

View File

@ -164,4 +164,14 @@ M._on_win_closed = function(winid)
winid_map[winid] = nil
end
M.schedule_wrap_before_vimenter = function(func)
return function(...)
if vim.v.vim_did_enter == 0 then
return vim.schedule_wrap(func)(...)
else
return func(...)
end
end
end
return M