mirror of
https://github.com/zoriya/lz.n.git
synced 2026-06-03 19:11:10 +00:00
fix: error when applying colorscheme in after hook on event trigger (#86)
This commit is contained in:
@@ -34,6 +34,7 @@ local function init()
|
||||
callback = function(event)
|
||||
on_colorscheme(event.match)
|
||||
end,
|
||||
nested = true,
|
||||
group = M.augroup,
|
||||
})
|
||||
end
|
||||
|
||||
@@ -150,6 +150,7 @@ local function add_event(event)
|
||||
vim.api.nvim_create_autocmd(event.event, {
|
||||
group = M.group,
|
||||
once = true,
|
||||
nested = true,
|
||||
pattern = event.pattern,
|
||||
callback = function(ev)
|
||||
if done or not state.has_pending_plugins(event.id) then
|
||||
@@ -157,10 +158,10 @@ local function add_event(event)
|
||||
end
|
||||
-- HACK: work-around for https://github.com/neovim/neovim/issues/25526
|
||||
done = true
|
||||
local st = get_state(ev.event, ev.buf, ev.data)
|
||||
local state_before_load = get_state(ev.event, ev.buf, ev.data)
|
||||
state.each_pending(event.id, loader.load)
|
||||
---@param s lz.n.EventOpts
|
||||
vim.iter(st):each(function(s)
|
||||
vim.iter(state_before_load):each(function(s)
|
||||
trigger(s)
|
||||
end)
|
||||
end,
|
||||
@@ -192,6 +193,7 @@ function M.post_load()
|
||||
elseif not vim.g.lz_n_did_create_deferred_ui_enter_autocmd then
|
||||
vim.api.nvim_create_autocmd("UIEnter", {
|
||||
once = true,
|
||||
nested = true,
|
||||
callback = deferred_ui_enter,
|
||||
})
|
||||
vim.g.lz_n_did_create_deferred_ui_enter_autocmd = true
|
||||
|
||||
@@ -126,6 +126,7 @@ local function add_keys(keys)
|
||||
if keys.ft then
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = keys.ft,
|
||||
nested = true,
|
||||
callback = function(event)
|
||||
if state.has_pending_plugins[keys.id] then
|
||||
add(event.buf)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
describe("nested events", function()
|
||||
it("lazy-loaded colorscheme triggered by UIEnter event", function()
|
||||
require("lz.n").load({
|
||||
{
|
||||
"sweetie.nvim",
|
||||
colorscheme = "sweetie",
|
||||
load = function()
|
||||
vim.g.sweetie_nvim_loaded = true
|
||||
end,
|
||||
},
|
||||
{
|
||||
"xyz",
|
||||
event = "UIEnter",
|
||||
after = function()
|
||||
pcall(vim.cmd.colorscheme, "sweetie")
|
||||
end,
|
||||
load = function() end,
|
||||
},
|
||||
})
|
||||
vim.api.nvim_exec_autocmds("UIEnter", {})
|
||||
assert.True(vim.g.sweetie_nvim_loaded)
|
||||
end)
|
||||
end)
|
||||
Reference in New Issue
Block a user