Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
585 changes: 203 additions & 382 deletions lua/zen/init.lua

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/scripts/init_with_zen.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
vim.cmd([[let &rtp.=','.getcwd()]])
vim.opt.packpath:prepend("deps")
vim.opt.packpath:prepend(vim.fn.getcwd() .. "/deps")

vim.o.columns = 240
vim.o.lines = 52
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/init_with_zen_min_width.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
vim.cmd([[let &rtp.=','.getcwd()]])
vim.opt.packpath:prepend("deps")
vim.opt.packpath:prepend(vim.fn.getcwd() .. "/deps")

vim.o.columns = 240
vim.o.lines = 52
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/init_with_zen_small.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
vim.cmd([[let &rtp.=','.getcwd()]])
vim.opt.packpath:prepend("deps")
vim.opt.packpath:prepend(vim.fn.getcwd() .. "/deps")

vim.o.columns = 140
vim.o.lines = 52
Expand Down
288 changes: 284 additions & 4 deletions tests/test_integrations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,44 @@ T["left integration"]["opening closes zen side buffer, closing reopens it"] = fu
})
end

T["left integration"]["opening a left integration preserves an existing top integration"] = function()
child.cmd("Git")
child.lua("vim.cmd('Fyler kind=split_left_most')")

Helpers.expect.layout(child, {
type = "col",
children = {
{ type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 },
{
type = "row",
children = {
{ type = "leaf", filetype = "fyler", buftype = "acwrite", width = 46, height = 24 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 24 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 24 },
},
},
},
})

child.cmd("close")
child.lua("vim.cmd('Fyler kind=split_left_most')")
child.cmd("close")

Helpers.expect.layout(child, {
type = "col",
children = {
{ type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 },
{
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 24 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 24 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 24 },
},
},
},
})
end

T["left integration"]["opening an integration should close the existing integration on the same side"] = function()
child.cmd("Fyler kind=split_left_most")
Expand All @@ -61,6 +99,45 @@ T["left integration"]["opening an integration should close the existing integrat
})
end

T["left integration"]["opening a left integration preserves an existing bottom integration"] = function()
child.cmd("Trouble diagnostics")
child.cmd("Fyler kind=split_left_most")

Helpers.expect.layout(child, {
type = "col",
children = {
{
type = "row",
children = {
{ type = "leaf", filetype = "fyler", buftype = "acwrite", width = 46, height = 39 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 39 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 39 },
},
},
{ type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 },
},
})

child.cmd("close")
child.cmd("Fyler kind=split_left_most")
child.cmd("close")

Helpers.expect.layout(child, {
type = "col",
children = {
{
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 39 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 39 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 39 },
},
},
{ type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 },
},
})
end

T["top integration"] = MiniTest.new_set({})

T["top integration"]["opening"] = function()
Expand Down Expand Up @@ -118,6 +195,70 @@ T["top integration"]["opening an integration should close the existing integrati
})
end

T["top integration"]["closing a stacked top split returns cursor to the integration below it"] = function()
-- initialize a real temporary git repo with user identity so that
-- "Git commit --allow-empty" works deterministically in CI
child.lua([[
local tmpdir = vim.fn.tempname()
vim.fn.mkdir(tmpdir, "p")
vim.fn.system({ "git", "init", tmpdir })
vim.fn.system({ "git", "-C", tmpdir, "config", "user.name", "Test" })
vim.fn.system({ "git", "-C", tmpdir, "config", "user.email", "test@test.com" })
vim.fn.chdir(tmpdir)
]])
child.cmd("Git")

Helpers.expect.layout(child, {
type = "col",
children = {
{ type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 },
{
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 24 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 24 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 24 },
},
},
},
})

-- move cursor to fugitive window and start a commit
child.lua([[
for _, win in ipairs(vim.api.nvim_list_wins()) do
local buf = vim.api.nvim_win_get_buf(win)
if vim.bo[buf].filetype == "fugitive" then
vim.api.nvim_set_current_win(win)
break
end
end
]])
child.cmd("Git commit --allow-empty")

-- close the commit editor (abort the commit)
child.cmd("bdelete!")

Comment on lines +236 to +240
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test invokes :Git commit --allow-empty, which can start a real git commit process and may leave persistent state in the checkout (e.g., .git/index.lock) or fail due to missing git user identity. That can make the CI test suite flaky and may impact later test cases executed in the same repo. Prefer simulating the “stacked top split” deterministically (e.g., create an aboveleft split above the fugitive window and close it) without running an actual commit.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner Author

@sand4rt sand4rt Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot i dont want fakes/mocks i want real behaviour init a git repo of needed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in d288c90. The test now initializes a real temporary git repo inside the child Neovim (via vim.fn.system), sets user.name and user.email locally, and chdirs into it — so :Git commit --allow-empty runs against a genuine git repo with proper identity, no mocks needed.

-- layout should be unchanged
Helpers.expect.layout(child, {
type = "col",
children = {
{ type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 },
{
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 24 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 24 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 24 },
},
},
},
})

-- cursor should be in the fugitive window
local ft = child.lua_get("vim.bo.filetype")
MiniTest.expect.equality(ft, "fugitive")
end

T["bottom integration"] = MiniTest.new_set({})

T["bottom integration"]["opening"] = function()
Expand Down Expand Up @@ -177,15 +318,93 @@ end

T["right integration"] = MiniTest.new_set({})

T["right integration"]["opening a right integration preserves an existing top integration"] = function()
child.cmd("Git")
child.cmd("Neotest summary open")

Helpers.expect.layout(child, {
type = "col",
children = {
{ type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 },
{
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 24 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 24 },
{ type = "leaf", filetype = "neotest-summary", buftype = "nofile", width = 46, height = 24 },
},
},
},
})

child.cmd("Neotest summary close")
child.cmd("Neotest summary open")
child.cmd("Neotest summary close")

Helpers.expect.layout(child, {
type = "col",
children = {
{ type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 },
{
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 24 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 24 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 24 },
},
},
},
})
end

T["right integration"]["opening a right integration preserves an existing bottom integration"] = function()
child.cmd("Trouble diagnostics")
child.cmd("Neotest summary open")

Helpers.expect.layout(child, {
type = "col",
children = {
{
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 39 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 39 },
{ type = "leaf", filetype = "neotest-summary", buftype = "nofile", width = 46, height = 39 },
},
},
{ type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 },
},
})

child.cmd("Neotest summary close")
child.cmd("Neotest summary open")
child.cmd("Neotest summary close")

Helpers.expect.layout(child, {
type = "col",
children = {
{
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 39 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 39 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 39 },
},
},
{ type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 },
},
})
end

T["right integration"]["opening closes zen side buffer, closing reopens it"] = function()
child.cmd("Neotest summary open")

Helpers.expect.layout(child, {
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 },
{ type = "leaf", filetype = "", buftype = "", width = 142, height = 50 },
{ type = "leaf", filetype = "neotest-summary", buftype = "nofile", width = 50, height = 50 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 50 },
{ type = "leaf", filetype = "neotest-summary", buftype = "nofile", width = 46, height = 50 },
},
})

Expand All @@ -208,8 +427,8 @@ T["right integration"]["opening an integration should close the existing integra
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 },
{ type = "leaf", filetype = "", buftype = "", width = 142, height = 50 },
{ type = "leaf", filetype = "neotest-summary", buftype = "nofile", width = 50, height = 50 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 50 },
{ type = "leaf", filetype = "neotest-summary", buftype = "nofile", width = 46, height = 50 },
},
})

Expand Down Expand Up @@ -257,6 +476,67 @@ T["right integration"]["opening an integration with table filetype"] = function(
})
end

T["combined"] = MiniTest.new_set({})

T["combined"]["opening a side integration preserves existing top and bottom integrations"] = function()
child.cmd("Git")
child.cmd("Trouble diagnostics")
child.cmd("Fyler kind=split_left_most")

Helpers.expect.layout(child, {
type = "col",
children = {
{ type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 },
{
type = "row",
children = {
{ type = "leaf", filetype = "fyler", buftype = "acwrite", width = 46, height = 13 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 13 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 13 },
},
},
{ type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 },
},
})

child.cmd("close")
child.cmd("Fyler kind=split_left_most")
child.cmd("close")

Helpers.expect.layout(child, {
type = "col",
children = {
{ type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 },
{
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 13 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 13 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 13 },
},
},
{ type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 },
},
})

child.cmd("Trouble close")

Helpers.expect.layout(child, {
type = "col",
children = {
{ type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 },
{
type = "row",
children = {
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 24 },
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 24 },
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 24 },
},
},
},
})
end

local min_width_child = MiniTest.new_child_neovim()

T["min_width"] = MiniTest.new_set({
Expand Down
Loading
Loading