From 59f5c1a550bc0558c98727aefd8eb45336f27870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Sat, 30 Mar 2024 00:31:45 +0100 Subject: [PATCH] fix(autocmds): wrong registered group (#338) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 📃 Summary on vim enter, the group for auto-enabling wasn't cleared, meaning the plugin would re-enable everytime a new buffer was entered --- lua/no-neck-pain/init.lua | 2 +- lua/no-neck-pain/main.lua | 11 ++++++++++- tests/test_autocmds.lua | 9 +++++---- tests/test_integrations.lua | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lua/no-neck-pain/init.lua b/lua/no-neck-pain/init.lua index 4488773..9a7425c 100644 --- a/lua/no-neck-pain/init.lua +++ b/lua/no-neck-pain/init.lua @@ -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 diff --git a/lua/no-neck-pain/main.lua b/lua/no-neck-pain/main.lua index 8a60244..55f9f50 100644 --- a/lua/no-neck-pain/main.lua +++ b/lua/no-neck-pain/main.lua @@ -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, diff --git a/tests/test_autocmds.lua b/tests/test_autocmds.lua index 9dfb00d..3b3ad1f 100644 --- a/tests/test_autocmds.lua +++ b/tests/test_autocmds.lua @@ -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() diff --git a/tests/test_integrations.lua b/tests/test_integrations.lua index c019ad2..8d4c28b 100644 --- a/tests/test_integrations.lua +++ b/tests/test_integrations.lua @@ -70,7 +70,7 @@ T["setup"]["overrides default values"] = function() outline = { position = "right", reopen = true, - } + }, }) end