Skip to content
Merged
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
6 changes: 6 additions & 0 deletions lua/zen/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ local opts = {
local state = {
[vim.api.nvim_get_current_tabpage()] = { left = nil, right = nil },
}
local is_creating_side_window = false

local function get_main_width()
local width = opts.main and opts.main.width
Expand All @@ -44,6 +45,7 @@ local function get_main_width()
end

local function create_window(position)
is_creating_side_window = true
if position == "left" then
vim.cmd("topleft vnew")
elseif position == "right" then
Expand All @@ -62,6 +64,7 @@ local function create_window(position)
vim.api.nvim_set_option_value("filetype", "zen-" .. position, { buf = buf_id })
vim.api.nvim_set_option_value("buftype", "nofile", { buf = buf_id })
vim.api.nvim_set_option_value("buflisted", false, { buf = buf_id })
is_creating_side_window = false

return vim.api.nvim_get_current_win()
end
Expand Down Expand Up @@ -565,6 +568,9 @@ local function setup(options)
if is_popup_window(vim.api.nvim_get_current_win()) then
return
end
if args.event == "WinNew" and is_creating_side_window then
return
end
local filetype = vim.bo[args.buf].filetype
local is_integration = is_buff_integration(args.buf)
if args.event == "BufWinEnter" or args.event == "WinNew" then
Expand Down
6 changes: 5 additions & 1 deletion tests/scripts/minimal_init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
vim.cmd([[let &rtp.=','.getcwd()]])
vim.opt.packpath:prepend("deps")

require("mini.test").setup()
require("mini.test").setup({
collect = {
emulate_busted = true,
},
})
113 changes: 53 additions & 60 deletions tests/test_autocmd.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
local Helpers = dofile("tests/scripts/helpers.lua")
local child = MiniTest.new_child_neovim()

local T = MiniTest.new_set({
hooks = {
pre_case = function()
child.restart({ "-u", "tests/scripts/init_with_zen.lua" })
end,
post_once = child.stop,
},
})

T["close zen side buffers on last main quit"] = function()
before_each(function()
child.restart({ "-u", "tests/scripts/init_with_zen.lua" })
end)

teardown(child.stop)

it("closes zen side buffers on last main quit", function()
Helpers.expect.layout(child, {
type = "row",
children = {
Expand All @@ -25,9 +22,9 @@ T["close zen side buffers on last main quit"] = function()
local STOPPED = 0
local exit_code = vim.fn.jobwait({ child.job.id }, 1000)[1]
MiniTest.expect.equality(exit_code, STOPPED)
end
end)

T["open zen side buffers on startup"] = function()
it("opens zen side buffers on startup", function()
Helpers.expect.layout(child, {
type = "row",
children = {
Expand All @@ -36,9 +33,9 @@ T["open zen side buffers on startup"] = function()
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 },
},
})
end
end)

T["do not open zen side buffers when there is not enough space"] = function()
it("does not open zen side buffers when there is not enough space", function()
child.restart({ "-u", "tests/scripts/init_with_zen_small.lua" })

Helpers.expect.layout(child, {
Expand All @@ -48,64 +45,60 @@ T["do not open zen side buffers when there is not enough space"] = function()
width = 140,
height = 50,
})
end

T["cursor does not enter zen side buffers"] = MiniTest.new_set({
hooks = {
pre_case = function()
child.restart({ "-u", "tests/scripts/init_with_zen.lua" })
child.cmd("edit test.lua")
end,
},
})
end)

T["cursor does not enter zen side buffers"]["from main"] = function()
child.cmd("wincmd h")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua")
describe("cursor does not enter zen side buffers", function()
before_each(function()
child.restart({ "-u", "tests/scripts/init_with_zen.lua" })
child.cmd("edit test.lua")
end)

child.cmd("wincmd l")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua")
end
it("from main", function()
child.cmd("wincmd h")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua")

T["cursor does not enter zen side buffers"]["from top integration"] = function()
child.cmd("Git")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive")
child.cmd("wincmd l")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua")
end)

child.cmd("wincmd j")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua")
it("from top integration", function()
child.cmd("Git")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive")

child.cmd("wincmd k")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive")
child.cmd("wincmd j")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua")

child.cmd("wincmd h")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive")
child.cmd("wincmd k")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive")

child.cmd("wincmd l")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive")
child.cmd("wincmd h")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive")

child.cmd("close")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua")
end
child.cmd("wincmd l")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive")

T["cursor does not enter zen side buffers"]["from bottom integration"] = function()
child.cmd("Trouble diagnostics open")
child.cmd("wincmd j")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble")
child.cmd("close")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua")
end)

child.cmd("wincmd k")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua")
it("from bottom integration", function()
child.cmd("Trouble diagnostics open")
child.cmd("wincmd j")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble")

child.cmd("wincmd j")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble")
child.cmd("wincmd k")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua")

child.cmd("wincmd h")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble")
child.cmd("wincmd j")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble")

child.cmd("wincmd l")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble")
child.cmd("wincmd h")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble")

child.cmd("close")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua")
end
child.cmd("wincmd l")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble")

return T
child.cmd("close")
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua")
end)
end)
Loading
Loading