Skip to content

Commit

Permalink
fix(autocmds): wrong registered group (#338)
Browse files Browse the repository at this point in the history
## 📃 Summary

on vim enter, the group for auto-enabling wasn't cleared, meaning the
plugin would re-enable everytime a new buffer was entered
  • Loading branch information
shortcuts committed Mar 29, 2024
1 parent 8532782 commit 59f5c1a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lua/no-neck-pain/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function NoNeckPain.setup(opts)
end, 20)
end)
end,
group = "NoNeckPainAutocmd",
group = "NoNeckPainVimEnterAutocmd",
desc = "Triggers until it finds the correct moment/buffer to enable the plugin.",
})
end
Expand Down
11 changes: 10 additions & 1 deletion lua/no-neck-pain/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,19 @@ function N.enable(scope)
return D.log(s, "no registered integration")
end

if p.event == "WinEnter" and #S.getUnregisteredWins(S) == 0 then
local unregistered = S.getUnregisteredWins(S)
if p.event == "WinEnter" and #unregistered == 0 then
return D.log(s, "no new windows")
end

if
p.event == "WinEnter"
and #unregistered == 1
and not S.isSupportedIntegration(S, s, unregistered[1])
then
return D.log(s, "encountered a new window, not an integration")
end

N.init(s, false, true)
end)
end,
Expand Down
9 changes: 5 additions & 4 deletions tests/test_autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ end
T["auto command"]["disabling clears VimEnter autocmd"] = function()
child.restart({ "-u", "scripts/init_auto_open.lua" })
Helpers.toggle(child)
Helpers.wait(child)

Helpers.expect.equality(
child.api.nvim_get_autocmds({ group = "NoNeckPainVimEnterAutocmd" }),
{}
)
-- errors because it doesn't exist
Helpers.expect.error(function()
child.api.nvim_get_autocmds({ group = "NoNeckPainVimEnterAutocmd" })
end)
end

T["auto command"]["does not shift when opening/closing float window"] = function()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_integrations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ T["setup"]["overrides default values"] = function()
outline = {
position = "right",
reopen = true,
}
},
})
end

Expand Down

0 comments on commit 59f5c1a

Please sign in to comment.