diff --git a/lua/no-neck-pain/main.lua b/lua/no-neck-pain/main.lua index ac4c35b..65ba4fe 100644 --- a/lua/no-neck-pain/main.lua +++ b/lua/no-neck-pain/main.lua @@ -163,9 +163,7 @@ function N.enable(scope) vim.api.nvim_create_autocmd({ "TabLeave" }, { callback = function(p) vim.schedule(function() - if - S.isActiveTabRegistered(S) and not vim.api.nvim_tabpage_is_valid(S.activeTab) - then + if not vim.api.nvim_tabpage_is_valid(S.activeTab) then S.refreshTabs(S, S.activeTab) D.log(p.event, "tab %d is now inactive", S.activeTab) else diff --git a/lua/no-neck-pain/state.lua b/lua/no-neck-pain/state.lua index a884b35..d540ebf 100644 --- a/lua/no-neck-pain/state.lua +++ b/lua/no-neck-pain/state.lua @@ -182,6 +182,8 @@ end ---@return table: the wins that are not in `tab`. ---@private function State:getUnregisteredWins(withCurr) + + return vim.tbl_filter(function(win) if A.isRelativeWindow(win) then return false @@ -272,20 +274,12 @@ function State:scanIntegrations(scope) return unregisteredIntegrations end ----Whether the `activeTab` is valid or not. ---- ----@return boolean ----@private -function State:isActiveTabValid() - return self.isActiveTabRegistered(self) and vim.api.nvim_tabpage_is_valid(self.activeTab) -end - ----Whether the `activeTab` is registered in the state or not. +---Whether the `activeTab` is registered in the state and valid. --- ---@return boolean ---@private function State:isActiveTabRegistered() - return self.hasTabs(self) and self.tabs[self.activeTab] ~= nil + return self.hasTabs(self) and self.tabs[self.activeTab] ~= nil and vim.api.nvim_tabpage_is_valid(self.activeTab) end ---Whether the side window is registered and enabled in the config or not. diff --git a/tests/test_API.lua b/tests/test_API.lua index e55c9ac..78952f7 100644 --- a/tests/test_API.lua +++ b/tests/test_API.lua @@ -244,7 +244,7 @@ T["enable"]["(single tab) sets state"] = function() right = 1002, }) - Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL) + Helpers.expect.state(child, "tabs[1].wins.vsplits", 1) Helpers.expect.state_type(child, "tabs[1].wins.integrations", "table") @@ -272,7 +272,7 @@ T["enable"]["(multiple tab) sets state"] = function() left = 1001, right = 1002, }) - Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL) + Helpers.expect.state(child, "tabs[1].wins.vsplits", 1) Helpers.expect.state_type(child, "tabs[1].wins.integrations", "table") @@ -296,7 +296,7 @@ T["enable"]["(multiple tab) sets state"] = function() left = 1004, right = 1005, }) - Helpers.expect.state(child, "tabs[2].wins.splits", vim.NIL) + Helpers.expect.state(child, "tabs[2].wins.vsplits", 3) Helpers.expect.state_type(child, "tabs[2].wins.integrations", "table") diff --git a/tests/test_integrations.lua b/tests/test_integrations.lua index bd744ae..f9f88ad 100644 --- a/tests/test_integrations.lua +++ b/tests/test_integrations.lua @@ -149,7 +149,7 @@ T["nvimdapui"]["keeps sides open"] = function() right = 1002, }) - Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL) + Helpers.expect.state(child, "tabs[1].wins.vsplits", 5) Helpers.expect.state(child, "tabs[1].wins.integrations.NvimDAPUI", { close = "lua require('dapui').close()", @@ -178,7 +178,7 @@ T["neotest"]["keeps sides open"] = function() child.lua([[require('neotest').summary.open()]]) vim.loop.sleep(50) - Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL) + Helpers.expect.state(child, "tabs[1].wins.vsplits", 3) Helpers.expect.state(child, "tabs[1].wins.integrations.neotest", { close = "lua require('neotest').summary.close()", @@ -207,7 +207,7 @@ T["outline"]["keeps sides open"] = function() child.cmd("Outline") vim.loop.sleep(50) - Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL) + Helpers.expect.state(child, "tabs[1].wins.vsplits", 1) Helpers.expect.state(child, "tabs[1].wins.integrations.outline", { close = "Outline", @@ -251,7 +251,7 @@ T["NvimTree"]["keeps sides open"] = function() right = 1002, }) - Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL) + Helpers.expect.state(child, "tabs[1].wins.vsplits", 1) Helpers.expect.state(child, "tabs[1].wins.integrations.NvimTree", { close = "NvimTreeClose", @@ -290,7 +290,7 @@ T["neo-tree"]["keeps sides open"] = function() right = 1002, }) - Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL) + Helpers.expect.state(child, "tabs[1].wins.vsplits", 1) Helpers.expect.state(child, "tabs[1].wins.integrations.NeoTree", { close = "Neotree close", @@ -321,7 +321,7 @@ T["TSPlayground"]["keeps sides open"] = function() child.cmd("TSPlaygroundToggle") vim.loop.sleep(50) - Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL) + Helpers.expect.state(child, "tabs[1].wins.vsplits", 3) Helpers.expect.equality(child.lua_get("vim.api.nvim_win_get_width(1004)"), 159) Helpers.expect.state(child, "tabs[1].wins.integrations.TSPlayground", { @@ -381,7 +381,7 @@ T["TSPlayground"]["reduces `left` side if only active when integration is on `ri child.cmd("TSPlaygroundToggle") vim.loop.sleep(50) - Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL) + Helpers.expect.state(child, "tabs[1].wins.vsplits", 1) Helpers.expect.equality(child.lua_get("vim.api.nvim_win_get_width(1003)"), 142) Helpers.expect.equality(child.lua_get("vim.api.nvim_win_get_width(1001)"), 15) @@ -401,7 +401,7 @@ T["TSPlayground"]["reduces `left` side if only active when integration is on `ri child.cmd("TSPlaygroundToggle") vim.loop.sleep(50) - Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL) + Helpers.expect.state(child, "tabs[1].wins.vsplits", 2) Helpers.expect.state(child, "tabs[1].wins.integrations.TSPlayground", { close = "TSPlaygroundToggle", @@ -441,7 +441,7 @@ T["aerial"]["keeps sides open"] = function() child.cmd("AerialToggle") - Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL) + Helpers.expect.state(child, "tabs[1].wins.vsplits", 1) Helpers.expect.equality(child.lua_get("vim.api.nvim_win_get_width(1004)"), 25) Helpers.expect.state(child, "tabs[1].wins.integrations.aerial.id", 1004) diff --git a/tests/test_tabs.lua b/tests/test_tabs.lua index 09f35c0..d00ceae 100644 --- a/tests/test_tabs.lua +++ b/tests/test_tabs.lua @@ -185,10 +185,6 @@ T["tabnew/tabclose"]["doesn't keep closed tabs in state"] = function() Helpers.expect.state(child, "tabs", { { id = 1, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = Co.INTEGRATIONS, @@ -197,6 +193,7 @@ T["tabnew/tabclose"]["doesn't keep closed tabs in state"] = function() left = 1001, right = 1002, }, + vsplits = 1, }, }, }) @@ -206,10 +203,6 @@ T["tabnew/tabclose"]["doesn't keep closed tabs in state"] = function() Helpers.expect.state(child, "tabs", { { id = 1, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = Co.INTEGRATIONS, @@ -218,14 +211,11 @@ T["tabnew/tabclose"]["doesn't keep closed tabs in state"] = function() left = 1001, right = 1002, }, + vsplits = 1, }, }, { id = 2, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = Co.INTEGRATIONS, @@ -234,6 +224,7 @@ T["tabnew/tabclose"]["doesn't keep closed tabs in state"] = function() left = 1004, right = 1005, }, + vsplits = 1, }, }, }) @@ -242,10 +233,6 @@ T["tabnew/tabclose"]["doesn't keep closed tabs in state"] = function() Helpers.expect.state(child, "tabs", { { id = 1, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = Co.INTEGRATIONS, @@ -254,6 +241,7 @@ T["tabnew/tabclose"]["doesn't keep closed tabs in state"] = function() left = 1001, right = 1002, }, + vsplits = 1, }, }, }) @@ -269,10 +257,6 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function() Helpers.expect.state(child, "tabs", { { id = 1, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = Co.INTEGRATIONS, @@ -281,6 +265,7 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function() left = 1001, right = 1002, }, + vsplits = 1, }, }, }) @@ -293,10 +278,6 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function() Helpers.expect.state(child, "tabs", { { id = 1, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = Co.INTEGRATIONS, @@ -305,14 +286,11 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function() left = 1001, right = 1002, }, + vsplits = 1, }, }, { id = 2, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = Co.INTEGRATIONS, @@ -321,6 +299,7 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function() left = 1004, right = 1005, }, + vsplits = 3, }, }, }) @@ -329,10 +308,6 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function() Helpers.expect.state(child, "tabs", { { id = 1, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = Co.INTEGRATIONS, @@ -341,6 +316,7 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function() left = 1001, right = 1002, }, + vsplits = 1, }, }, }) @@ -349,10 +325,6 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function() Helpers.expect.state(child, "tabs", { { id = 1, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = Co.INTEGRATIONS, @@ -361,14 +333,11 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function() left = 1001, right = 1002, }, + vsplits = 1, }, }, { id = 2, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = Co.INTEGRATIONS, @@ -377,6 +346,7 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function() left = 1006, right = 1007, }, + vsplits = 3, }, }, }) @@ -386,10 +356,6 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function() Helpers.expect.state(child, "tabs", { { id = 1, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = Co.INTEGRATIONS, @@ -398,14 +364,11 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function() left = 1001, right = 1002, }, + vsplits = 1, }, }, { id = 2, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = Co.INTEGRATIONS, @@ -414,6 +377,7 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function() left = 1006, right = 1007, }, + vsplits = 3, }, }, }) @@ -443,10 +407,6 @@ T["tabnew/tabclose"]["does not pick tab 1 for the first active tab"] = function( Helpers.expect.state(child, "activeTab", 2) Helpers.expect.state(child, "tabs[2]", { id = 2, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = Co.INTEGRATIONS, @@ -455,6 +415,7 @@ T["tabnew/tabclose"]["does not pick tab 1 for the first active tab"] = function( left = 1002, right = 1003, }, + vsplits = 1, }, }) @@ -468,10 +429,6 @@ T["tabnew/tabclose"]["does not pick tab 1 for the first active tab"] = function( Helpers.toggle(child) Helpers.expect.state(child, "tabs[1]", { id = 1, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = { @@ -521,14 +478,11 @@ T["tabnew/tabclose"]["does not pick tab 1 for the first active tab"] = function( left = 1004, right = 1005, }, + vsplits = 3, }, }) Helpers.expect.state(child, "tabs[2]", { id = 2, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = Co.INTEGRATIONS, @@ -537,6 +491,7 @@ T["tabnew/tabclose"]["does not pick tab 1 for the first active tab"] = function( left = 1002, right = 1003, }, + vsplits = 1, }, }) end @@ -562,10 +517,6 @@ T["tabnew/tabclose"]["keep state synchronized on second tab"] = function() Helpers.expect.state(child, "activeTab", 2) Helpers.expect.state(child, "tabs[2]", { id = 2, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = Co.INTEGRATIONS, @@ -592,10 +543,6 @@ T["tabnew/tabclose"]["keep state synchronized on second tab"] = function() Helpers.expect.state(child, "tabs[1]", vim.NIL) Helpers.expect.state(child, "tabs[2]", { id = 2, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = Co.INTEGRATIONS, @@ -626,10 +573,6 @@ T["tabnew/tabclose"]["does not close nvim when quitting tab if some are left"] = Helpers.expect.state(child, "enabled", true) Helpers.expect.state(child, "tabs[1]", { id = 1, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = Co.INTEGRATIONS, @@ -643,10 +586,6 @@ T["tabnew/tabclose"]["does not close nvim when quitting tab if some are left"] = Helpers.expect.state(child, "activeTab", 2) Helpers.expect.state(child, "tabs[2]", { id = 2, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = Co.INTEGRATIONS, @@ -663,10 +602,6 @@ T["tabnew/tabclose"]["does not close nvim when quitting tab if some are left"] = Helpers.expect.state(child, "activeTab", 1) Helpers.expect.state(child, "tabs[1]", { id = 1, - layers = { - split = 1, - vsplit = 1, - }, scratchPadEnabled = false, wins = { integrations = Co.INTEGRATIONS,