Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(enableOnVimEnter): prevent flicker on enter #429

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions lua/no-neck-pain/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion lua/no-neck-pain/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading