diff --git a/lua/no-neck-pain/init.lua b/lua/no-neck-pain/init.lua index 3ad263a..04bb369 100644 --- a/lua/no-neck-pain/init.lua +++ b/lua/no-neck-pain/init.lua @@ -107,21 +107,21 @@ function NoNeckPain.setup(opts) end if _G.NoNeckPain.config.autocmds.enableOnVimEnter then - vim.api.nvim_create_autocmd({ "BufEnter" }, { + vim.api.nvim_create_autocmd({ "BufWinEnter" }, { pattern = "*", callback = function() - vim.schedule(function() - if _G.NoNeckPain.state ~= nil and _G.NoNeckPain.state.enabled then - return - end + local scope = "enable_on_vim_enter" + - NoNeckPain.enable() + main.enable(scope) - api.debounce("enable_on_vim_enter", function() - if _G.NoNeckPain.state ~= nil then - pcall(vim.api.nvim_del_augroup_by_name, "NoNeckPainVimEnterAutocmd") - end - end, 20) + api.debounce(scope, function() + if _G.NoNeckPain.state ~= nil then + pcall(vim.api.nvim_del_augroup_by_name, "NoNeckPainVimEnterAutocmd") + end + end) + vim.schedule(function() + main.init(scope) end) end, group = "NoNeckPainVimEnterAutocmd", diff --git a/lua/no-neck-pain/main.lua b/lua/no-neck-pain/main.lua index ed822e3..61c9db3 100644 --- a/lua/no-neck-pain/main.lua +++ b/lua/no-neck-pain/main.lua @@ -326,7 +326,7 @@ function main.enable(scope) desc = "keeps track of the state after closing windows and deleting buffers", }) - vim.api.nvim_create_autocmd({ "WinLeave" }, { + vim.api.nvim_create_autocmd({ "WinEnter" }, { callback = function(p) vim.schedule(function() p.event = string.format("%s:skip_entering", p.event)