Skip to content

Commit 6fa941a

Browse files
committed
fix: resizing with top/bottom integrations
1 parent a4325a6 commit 6fa941a

6 files changed

Lines changed: 203 additions & 14 deletions

File tree

‎.luarc.json‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"diagnostics": {
33
"globals": [
4-
"dofile"
4+
"dofile",
5+
"MiniTest"
56
]
67
},
78
"workspace": {
89
"library": [
910
"$VIMRUNTIME",
10-
"deps/mini.nvim"
11+
"deps/pack/testing/start/mini.nvim"
1112
]
1213
}
1314
}

‎Makefile‎

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,41 @@
11
DEPS_DIR := $(CURDIR)/deps
2+
START_DIR := $(DEPS_DIR)/pack/testing/start
23

34
.PHONY: test deps
45

5-
# Download mini.nvim if not present, then run all tests
66
test: deps
77
nvim --headless -u tests/scripts/minimal_init.lua -c "lua MiniTest.run()"
88

9-
# Clone mini.nvim into deps/
10-
deps:
11-
@if [ ! -d "$(DEPS_DIR)/mini.nvim" ]; then \
12-
echo "Downloading mini.nvim..."; \
13-
mkdir -p "$(DEPS_DIR)"; \
14-
git clone --depth 1 https://github.com/echasnovski/mini.nvim "$(DEPS_DIR)/mini.nvim"; \
15-
fi
9+
deps: \
10+
$(START_DIR)/mini.nvim \
11+
$(START_DIR)/vim-fugitive \
12+
$(START_DIR)/fyler.nvim \
13+
$(START_DIR)/trouble.nvim \
14+
$(START_DIR)/neotest \
15+
$(START_DIR)/nvim-nio \
16+
$(START_DIR)/plenary.nvim \
17+
$(START_DIR)/fixcursorhold
18+
19+
$(START_DIR)/mini.nvim:
20+
git clone --depth 1 https://github.com/echasnovski/mini.nvim $@
21+
22+
$(START_DIR)/vim-fugitive:
23+
git clone --depth 1 https://github.com/tpope/vim-fugitive $@
24+
25+
$(START_DIR)/fyler.nvim:
26+
git clone --depth 1 https://github.com/A7Lavinraj/fyler.nvim $@
27+
28+
$(START_DIR)/trouble.nvim:
29+
git clone --depth 1 https://github.com/folke/trouble.nvim $@
30+
31+
$(START_DIR)/neotest:
32+
git clone --depth 1 https://github.com/nvim-neotest/neotest $@
33+
34+
$(START_DIR)/nvim-nio:
35+
git clone --depth 1 https://github.com/nvim-neotest/nvim-nio $@
36+
37+
$(START_DIR)/plenary.nvim:
38+
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim $@
39+
40+
$(START_DIR)/fixcursorhold:
41+
git clone --depth 1 https://github.com/antoinemadec/FixCursorHold.nvim $@

‎lua/zen/init.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ local function is_buff_integration(buf)
129129
if filetype == "zen-left" or filetype == "zen-right" then
130130
return true
131131
end
132-
for _, position in ipairs({ "left", "right" }) do
132+
for _, position in ipairs({ "left", "right", "top", "bottom" }) do
133133
for _, integration in ipairs(opts[position] or {}) do
134134
---@diagnostic disable-next-line: undefined-field
135135
if type(integration) == "table" and is_filetype(filetype, integration.filetype) then

‎tests/scripts/init_with_zen.lua‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
vim.cmd([[let &rtp.=','.getcwd()]])
2-
vim.cmd("set rtp+=deps/mini.nvim")
2+
vim.opt.packpath:prepend("deps")
33

44
vim.o.columns = 240
55
vim.o.lines = 52
66

77
require("mini.test").setup()
8-
require("zen").setup()
8+
require("trouble").setup({ open_no_results = true })
9+
require("zen").setup({
10+
top = {
11+
{ filetype = "fugitive" },
12+
},
13+
bottom = {
14+
{ filetype = "trouble" },
15+
},
16+
left = {
17+
min_width = 46,
18+
{ filetype = "fyler" },
19+
},
20+
right = {
21+
min_width = 46,
22+
{ filetype = "neotest-summary" },
23+
},
24+
})

‎tests/scripts/minimal_init.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
vim.cmd([[let &rtp.=','.getcwd()]])
2-
vim.cmd("set rtp+=deps/mini.nvim")
2+
vim.opt.packpath:prepend("deps")
33

44
require("mini.test").setup()

‎tests/test_resizing.lua‎

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
local Helpers = dofile("tests/scripts/helpers.lua")
2+
local child = MiniTest.new_child_neovim()
3+
4+
local T = MiniTest.new_set({
5+
hooks = {
6+
pre_case = function()
7+
child.restart({ "-u", "tests/scripts/init_with_zen.lua" })
8+
end,
9+
post_once = child.stop,
10+
},
11+
})
12+
13+
T["resizing below minimum width closes the side buffers"] = function()
14+
child.cmd("set columns-=100")
15+
child.cmd("doautocmd VimResized")
16+
17+
Helpers.expect.layout(child, {
18+
type = "leaf",
19+
filetype = "",
20+
buftype = "",
21+
width = 140,
22+
height = 50,
23+
})
24+
end
25+
26+
T["resizing above minimum width reopens the side buffers"] = function()
27+
child.cmd("set columns-=100")
28+
child.cmd("doautocmd VimResized")
29+
30+
child.cmd("set columns+=100")
31+
child.cmd("doautocmd VimResized")
32+
33+
Helpers.expect.layout(child, {
34+
type = "row",
35+
children = {
36+
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 },
37+
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 50 },
38+
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 },
39+
},
40+
})
41+
end
42+
43+
T["with top integration"] = MiniTest.new_set({})
44+
45+
T["with top integration"]["resizing below minimum width closes the side buffers"] = function()
46+
child.cmd("Git")
47+
48+
child.cmd("set columns-=100")
49+
child.cmd("doautocmd VimResized")
50+
51+
Helpers.expect.layout(child, {
52+
type = "col",
53+
children = {
54+
{ type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 140, height = 25 },
55+
{ type = "leaf", filetype = "", buftype = "", width = 140, height = 24 },
56+
},
57+
})
58+
end
59+
60+
T["with top integration"]["resizing above minimum width reopens the side buffers"] = function()
61+
child.cmd("Git")
62+
63+
child.cmd("set columns-=100")
64+
child.cmd("doautocmd VimResized")
65+
66+
child.cmd("set columns+=100")
67+
child.cmd("doautocmd VimResized")
68+
69+
Helpers.expect.layout(child, {
70+
type = "col",
71+
children = {
72+
{ type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 },
73+
{
74+
type = "row",
75+
children = {
76+
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 24 },
77+
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 24 },
78+
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 24 },
79+
},
80+
},
81+
},
82+
})
83+
end
84+
85+
T["with bottom integration"] = MiniTest.new_set({})
86+
87+
T["with bottom integration"]["resizing below minimum width closes the side buffers"] = function()
88+
child.cmd("Trouble diagnostics")
89+
90+
child.cmd("set columns-=100")
91+
child.cmd("doautocmd VimResized")
92+
93+
Helpers.expect.layout(child, {
94+
type = "col",
95+
children = {
96+
{ type = "leaf", filetype = "", buftype = "", width = 140, height = 39 },
97+
{ type = "leaf", filetype = "trouble", buftype = "nofile", width = 140, height = 10 },
98+
},
99+
})
100+
end
101+
102+
T["with bottom integration"]["resizing above minimum width reopens the side buffers"] = function()
103+
child.cmd("Trouble diagnostics")
104+
105+
child.cmd("set columns-=100")
106+
child.cmd("doautocmd VimResized")
107+
108+
child.cmd("set columns+=100")
109+
child.cmd("doautocmd VimResized")
110+
111+
Helpers.expect.layout(child, {
112+
type = "col",
113+
children = {
114+
{
115+
type = "row",
116+
children = {
117+
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 39 },
118+
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 39 },
119+
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 39 },
120+
},
121+
},
122+
{ type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 },
123+
},
124+
})
125+
end
126+
127+
T["with top and bottom integration"] = MiniTest.new_set({})
128+
129+
T["with top and bottom integration"]["resizing below minimum width closes the side buffers"] = function()
130+
child.cmd("Git")
131+
child.cmd("Trouble diagnostics")
132+
133+
child.cmd("set columns-=100")
134+
child.cmd("doautocmd VimResized")
135+
136+
Helpers.expect.layout(child, {
137+
type = "col",
138+
children = {
139+
{ type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 140, height = 25 },
140+
{ type = "leaf", filetype = "", buftype = "", width = 140, height = 13 },
141+
{ type = "leaf", filetype = "trouble", buftype = "nofile", width = 140, height = 10 },
142+
},
143+
})
144+
end
145+
146+
return T

0 commit comments

Comments
 (0)