From 8bdc4ea8a282476936f2bcb966f98bda02c1bf59 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Sun, 26 May 2024 21:48:44 +0200 Subject: [PATCH 1/2] fix(neotree): close if last window --- scripts/init_with_neotree.lua | 1 + tests/test_integrations.lua | 48 +++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/scripts/init_with_neotree.lua b/scripts/init_with_neotree.lua index 8dfbb738..c749409d 100644 --- a/scripts/init_with_neotree.lua +++ b/scripts/init_with_neotree.lua @@ -16,6 +16,7 @@ require("neo-tree").setup({ window = { width = 1, }, + close_if_last_window = true, }) require("mini.test").setup() require("no-neck-pain").setup({ diff --git a/tests/test_integrations.lua b/tests/test_integrations.lua index 2c9abc66..ec554ad2 100644 --- a/tests/test_integrations.lua +++ b/tests/test_integrations.lua @@ -301,6 +301,54 @@ T["neo-tree"]["keeps sides open"] = function() }) end +T["neo-tree"]["close_if_last_window"] = function() + child.restart({ "-u", "scripts/init_with_neotree.lua", "foo" }) + child.set_size(5, 300) + + Helpers.toggle(child) + + Helpers.expect.equality(Helpers.winsInTab(child), { 1001, 1000, 1002 }) + + Helpers.expect.state(child, "enabled", true) + Helpers.expect.state(child, "tabs[1].wins.main", { + curr = 1000, + left = 1001, + right = 1002, + }) + + child.cmd("Neotree reveal") + child.loop.sleep(50) + + Helpers.expect.equality(Helpers.winsInTab(child), { 1004, 1001, 1000, 1002 }) + + Helpers.expect.state(child, "tabs[1].wins.main", { + curr = 1000, + left = 1001, + right = 1002, + }) + + Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL) + + Helpers.expect.state(child, "tabs[1].wins.integrations.NeoTree", { + close = "Neotree close", + fileTypePattern = "neo-tree", + id = 1004, + open = "Neotree reveal", + width = 2, + }) + + child.fn.win_gotoid(1000) + + Helpers.expect.equality(Helpers.winsInTab(child), { 1004, 1001, 1000, 1002 }) + + child.cmd("q") + + -- invalid channel + Helpers.expect.error(function() + Helpers.expect.equality(Helpers.winsInTab(child), { 1004, 1001, 1000, 1002 }) + end) +end + T["TSPlayground"] = MiniTest.new_set() T["TSPlayground"]["keeps sides open"] = function() From c0e9364f9fd56acc74deb3a6767464557c8daa19 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Fri, 31 May 2024 10:02:22 +0200 Subject: [PATCH 2/2] chore: match @sand4rt input --- lua/no-neck-pain/util/constants.lua | 4 ++-- scripts/init_with_neotree.lua | 5 +++-- tests/test_integrations.lua | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lua/no-neck-pain/util/constants.lua b/lua/no-neck-pain/util/constants.lua index 65394eac..64399e42 100644 --- a/lua/no-neck-pain/util/constants.lua +++ b/lua/no-neck-pain/util/constants.lua @@ -44,8 +44,8 @@ Co.INTEGRATIONS = { }, NeoTree = { fileTypePattern = "neo-tree", - close = "Neotree close", - open = "Neotree reveal", + close = "Neotree", + open = "Neotree", }, neotest = { fileTypePattern = "neotest", diff --git a/scripts/init_with_neotree.lua b/scripts/init_with_neotree.lua index c749409d..54797caf 100644 --- a/scripts/init_with_neotree.lua +++ b/scripts/init_with_neotree.lua @@ -14,13 +14,14 @@ require("neo-tree").setup({ }, }, window = { - width = 1, + width = 20, }, close_if_last_window = true, }) require("mini.test").setup() require("no-neck-pain").setup({ - width = 1, + width = 20, minSideBufferWidth = 0, integrations = { NeoTree = { reopen = true } }, + autocmds = { skipEnteringNoNeckPainBuffer = true } }) diff --git a/tests/test_integrations.lua b/tests/test_integrations.lua index ec554ad2..d56bae66 100644 --- a/tests/test_integrations.lua +++ b/tests/test_integrations.lua @@ -316,7 +316,7 @@ T["neo-tree"]["close_if_last_window"] = function() right = 1002, }) - child.cmd("Neotree reveal") + child.cmd("Neotree") child.loop.sleep(50) Helpers.expect.equality(Helpers.winsInTab(child), { 1004, 1001, 1000, 1002 }) @@ -330,10 +330,10 @@ T["neo-tree"]["close_if_last_window"] = function() Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL) Helpers.expect.state(child, "tabs[1].wins.integrations.NeoTree", { - close = "Neotree close", + close = "Neotree", fileTypePattern = "neo-tree", id = 1004, - open = "Neotree reveal", + open = "Neotree", width = 2, })