Skip to content

Commit

Permalink
fix: only schedule_wrap when necessary (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Aug 28, 2022
1 parent be2ef16 commit 232b6b3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lua/dressing/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
})
Expand Down
3 changes: 2 additions & 1 deletion lua/dressing/select/init.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions lua/dressing/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 232b6b3

Please sign in to comment.