diff --git a/lua/no-neck-pain/init.lua b/lua/no-neck-pain/init.lua index 6767045..b35810a 100644 --- a/lua/no-neck-pain/init.lua +++ b/lua/no-neck-pain/init.lua @@ -24,7 +24,7 @@ function NoNeckPain.toggleScratchPad() _G.NoNeckPain.config = C.options end - A.debounce("publicAPI_toggleScratchPad", M.toggleScratchPad) + M.toggleScratchPad() end --- Sets the config `width` to the given `width` value and resizes the NoNeckPain windows. @@ -45,9 +45,7 @@ function NoNeckPain.resize(width) _G.NoNeckPain.config = vim.tbl_deep_extend("keep", { width = width }, _G.NoNeckPain.config) end - A.debounce("publicAPI_resize", function(scope) - M.init(scope, false) - end) + M.init("publicAPI_resize", false) end --- Toggles the config `${side}.enabled` and re-inits the plugin. @@ -99,7 +97,7 @@ function NoNeckPain.setup(opts) end _G.NoNeckPain.config = C.defaults(opts) - A.debounce("ColorScheme", M.init) + M.init("ColorScheme") end) end, group = "NoNeckPainAutocmd", diff --git a/lua/no-neck-pain/main.lua b/lua/no-neck-pain/main.lua index 3c0b063..1525f1b 100644 --- a/lua/no-neck-pain/main.lua +++ b/lua/no-neck-pain/main.lua @@ -187,30 +187,30 @@ function N.enable(scope) vim.api.nvim_create_autocmd({ "WinEnter" }, { callback = function(p) - A.debounce(string.format("%s:splits", p.event), function(debounceScope) + vim.schedule(function() if not S.hasTabs(S) or E.skip(S.getTab(S)) then - return D.log(debounceScope, "skip split logic") + return D.log(p.event, "skip split logic") end if S.checkSides(S, "and", false) then - return D.log(debounceScope, "skip split logic: no side buffer") + return D.log(p.event, "skip split logic: no side buffer") end if S.isSideTheActiveWin(S, "curr") then - return D.log(debounceScope, "skip split logic: current win") + return D.log(p.event, "skip split logic: current win") end -- an integration isn't considered as a split - local isSupportedIntegration = S.isSupportedIntegration(S, debounceScope, nil) + local isSupportedIntegration = S.isSupportedIntegration(S, p.event, nil) if isSupportedIntegration then - return D.log(debounceScope, "skip split logic: integration") + return D.log(p.event, "skip split logic: integration") end local wins = S.getUnregisteredWins(S) if #wins ~= 1 then return D.log( - debounceScope, + p.event, "skip split logic: no new or too many unregistered windows" ) end @@ -221,7 +221,7 @@ function N.enable(scope) S.setSplit(S, { id = focusedWin, vertical = isVSplit }) if isVSplit then - N.init(debounceScope) + N.init(p.event) end end) end, @@ -330,27 +330,24 @@ function N.enable(scope) vim.api.nvim_create_autocmd({ "WinEnter", "WinClosed" }, { callback = function(p) - A.debounce(string.format("%s:integrations", p.event), function(debounceScope) + vim.schedule(function() if not S.hasTabs(S) or not S.isActiveTabRegistered(S) or E.skip(S.getTab(S)) then - return D.log(debounceScope, "skip integrations logic") + return D.log(p.event, "skip integrations logic") end if S.wantsSides(S) and S.checkSides(S, "and", false) then - return D.log(debounceScope, "skip integrations logic: no side buffer") + return D.log(p.event, "skip integrations logic: no side buffer") end if p.event == "WinClosed" and not S.hasIntegrations(S) then - return D.log( - debounceScope, - "skip integrations logic: no registered integration" - ) + return D.log(p.event, "skip integrations logic: no registered integration") end if p.event == "WinEnter" and #S.getUnregisteredWins(S) == 0 then - return D.log(debounceScope, "skip integrations logic: no new windows") + return D.log(p.event, "skip integrations logic: no new windows") end - N.init(debounceScope, false, true) + N.init(p.event, false, true) end) end, group = augroupName, diff --git a/lua/no-neck-pain/state.lua b/lua/no-neck-pain/state.lua index b583157..5cdfd00 100644 --- a/lua/no-neck-pain/state.lua +++ b/lua/no-neck-pain/state.lua @@ -72,22 +72,29 @@ function State:closeIntegration() for name, opts in pairs(self.tabs[self.activeTab].wins.integrations) do if opts.id ~= nil and opts.close ~= nil then + local scope = string.format("closeIntegration:%s", name) -- if this integration doesn't belong to any side we don't have to -- close it to redraw side buffers local side = _G.NoNeckPain.config.integrations[name].position if side ~= "left" and side ~= "right" then + D.log(scope, "skipped because not a side integration") + goto continue end -- first element in the current wins list means it's the far left one, -- if the integration is already at this spot then we don't have to close anything if side == "left" and wins[1] == self.tabs[self.activeTab].wins.main[side] then + D.log(scope, "skipped because already at the far left side") + goto continue end -- last element in the current wins list means it's the far right one, -- if the integration is already at this spot then we don't have to close anything if side == "right" and wins[#wins] == self.tabs[self.activeTab].wins.main[side] then + D.log(scope, "skipped because already at the far right side") + goto continue end diff --git a/tests/test_integrations.lua b/tests/test_integrations.lua index 00ba9f7..4868c19 100644 --- a/tests/test_integrations.lua +++ b/tests/test_integrations.lua @@ -284,7 +284,7 @@ T["TSPlayground"]["keeps sides open"] = function() fileTypePattern = "tsplayground", id = 1004, open = "TSPlaygroundToggle", - width = 198, + width = 346, }) Helpers.expect.state(child, "tabs[1].wins.main", {