Skip to content

Commit

Permalink
Styling
Browse files Browse the repository at this point in the history
  • Loading branch information
MisanthropicBit committed May 26, 2024
1 parent 218718e commit 50e0a2e
Showing 1 changed file with 160 additions and 109 deletions.
269 changes: 160 additions & 109 deletions tests/resize_adjust_neighbors_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,30 @@ describe("resize", function()
vim.api.nvim_set_current_win(win_id)

local _, main_col_before, main_width_before, _ = get_win_pos_and_dimensions(win_id)
local _, col_before1, width_before1, _ = get_win_pos_and_dimensions(layout["neighbor1"])
local _, col_before2, width_before2, _ = get_win_pos_and_dimensions(layout["neighbor2"])
local _, col_before3, width_before3, _ = get_win_pos_and_dimensions(layout["neighbor3"])
local _, bottom_col_before, bottom_width_before, _ = get_win_pos_and_dimensions(layout["bottom neighbor"])
local _, col_before4, width_before4, _ = get_win_pos_and_dimensions(layout["neighbor4"])
local _, col_before1, width_before1, _ =
get_win_pos_and_dimensions(layout["neighbor1"])
local _, col_before2, width_before2, _ =
get_win_pos_and_dimensions(layout["neighbor2"])
local _, col_before3, width_before3, _ =
get_win_pos_and_dimensions(layout["neighbor3"])
local _, bottom_col_before, bottom_width_before, _ =
get_win_pos_and_dimensions(layout["bottom neighbor"])
local _, col_before4, width_before4, _ =
get_win_pos_and_dimensions(layout["neighbor4"])

winmove.resize_window(win_id, "l", count, winmove.ResizeAnchor.TopLeft)

local _, main_col_after, main_width_after, _ = get_win_pos_and_dimensions(win_id)
local _, col_after1, width_after1, _ = get_win_pos_and_dimensions(layout["neighbor1"])
local _, col_after2, width_after2, _ = get_win_pos_and_dimensions(layout["neighbor2"])
local _, col_after3, width_after3, _ = get_win_pos_and_dimensions(layout["neighbor3"])
local _, bottom_col_after, bottom_width_after, _ = get_win_pos_and_dimensions(layout["bottom neighbor"])
local _, col_after4, width_after4, _ = get_win_pos_and_dimensions(layout["neighbor4"])
local _, col_after1, width_after1, _ =
get_win_pos_and_dimensions(layout["neighbor1"])
local _, col_after2, width_after2, _ =
get_win_pos_and_dimensions(layout["neighbor2"])
local _, col_after3, width_after3, _ =
get_win_pos_and_dimensions(layout["neighbor3"])
local _, bottom_col_after, bottom_width_after, _ =
get_win_pos_and_dimensions(layout["bottom neighbor"])
local _, col_after4, width_after4, _ =
get_win_pos_and_dimensions(layout["neighbor4"])

assert.are.same(main_col_before, main_col_after)
assert.are.same(main_width_before + count, main_width_after)
Expand Down Expand Up @@ -163,20 +173,30 @@ describe("resize", function()
vim.api.nvim_set_current_win(win_id)

local _, main_col_before, main_width_before, _ = get_win_pos_and_dimensions(win_id)
local _, col_before1, width_before1, _ = get_win_pos_and_dimensions(layout["neighbor1"])
local _, col_before2, width_before2, _ = get_win_pos_and_dimensions(layout["neighbor2"])
local _, col_before3, width_before3, _ = get_win_pos_and_dimensions(layout["neighbor3"])
local _, bottom_col_before, bottom_width_before, _ = get_win_pos_and_dimensions(layout["bottom neighbor"])
local _, col_before4, width_before4, _ = get_win_pos_and_dimensions(layout["neighbor4"])
local _, col_before1, width_before1, _ =
get_win_pos_and_dimensions(layout["neighbor1"])
local _, col_before2, width_before2, _ =
get_win_pos_and_dimensions(layout["neighbor2"])
local _, col_before3, width_before3, _ =
get_win_pos_and_dimensions(layout["neighbor3"])
local _, bottom_col_before, bottom_width_before, _ =
get_win_pos_and_dimensions(layout["bottom neighbor"])
local _, col_before4, width_before4, _ =
get_win_pos_and_dimensions(layout["neighbor4"])

winmove.resize_window(win_id, "h", count, winmove.ResizeAnchor.BottomRight)

local _, main_col_after, main_width_after, _ = get_win_pos_and_dimensions(win_id)
local _, col_after1, width_after1, _ = get_win_pos_and_dimensions(layout["neighbor1"])
local _, col_after2, width_after2, _ = get_win_pos_and_dimensions(layout["neighbor2"])
local _, col_after3, width_after3, _ = get_win_pos_and_dimensions(layout["neighbor3"])
local _, bottom_col_after, bottom_width_after, _ = get_win_pos_and_dimensions(layout["bottom neighbor"])
local _, col_after4, width_after4, _ = get_win_pos_and_dimensions(layout["neighbor4"])
local _, col_after1, width_after1, _ =
get_win_pos_and_dimensions(layout["neighbor1"])
local _, col_after2, width_after2, _ =
get_win_pos_and_dimensions(layout["neighbor2"])
local _, col_after3, width_after3, _ =
get_win_pos_and_dimensions(layout["neighbor3"])
local _, bottom_col_after, bottom_width_after, _ =
get_win_pos_and_dimensions(layout["bottom neighbor"])
local _, col_after4, width_after4, _ =
get_win_pos_and_dimensions(layout["neighbor4"])

assert.are.same(main_col_before - count, main_col_after)
assert.are.same(main_width_before + count, main_width_after)
Expand All @@ -198,110 +218,141 @@ describe("resize", function()
end)
end)

it("resizes towards multiple sibling windows and respects window dimension settings", function()
given(function()
local layout = make_layout({
"row",
{
"neighbor1",
it(
"resizes towards multiple sibling windows and respects window dimension settings",
function()
given(function()
local layout = make_layout({
"row",
{
"col",
"neighbor1",
{
"col",
{
"row",
{ "neighbor2", "neighbor3", "main" },
{
"row",
{ "neighbor2", "neighbor3", "main" },
},
"bottom neighbor",
},
"bottom neighbor",
},
"neighbor4",
},
"neighbor4",
},
})
})

local win_id = layout["main"]
local win_id = layout["main"]

assert.matches_winlayout(vim.fn.winlayout(), {
"row",
{
{ "leaf" },
assert.matches_winlayout(vim.fn.winlayout(), {
"row",
{
"col",
{ "leaf" },
{
"col",
{
"row",
{
{ "leaf" },
{ "leaf" },
{ "leaf" },
"row",
{
{ "leaf" },
{ "leaf" },
{ "leaf" },
},
},
{ "leaf" },
},
{ "leaf" },
},
{ "leaf" },
},
{ "leaf" },
},
})

---@type table<integer, integer>
local minwidth_map = {}

for _, _win_id in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
vim.api.nvim_win_call(_win_id, function()
local minwidth = vim.api.nvim_win_get_width(win_id) - count * 3
vim.opt_local.signcolumn = "no"
vim.opt_local.winwidth = minwidth
minwidth_map[_win_id] = minwidth
end)
end

vim.api.nvim_set_current_win(win_id)

local _, _, main_width_before, _ = get_win_pos_and_dimensions(win_id)
local _, col_before1, _, _ = get_win_pos_and_dimensions(layout["neighbor1"])
local _, _, _, _ = get_win_pos_and_dimensions(layout["neighbor2"])
local _, _, _, _ = get_win_pos_and_dimensions(layout["neighbor3"])
local _, _, _, _ = get_win_pos_and_dimensions(layout["bottom neighbor"])
local _, col_before4, width_before4, _ = get_win_pos_and_dimensions(layout["neighbor4"])

for _ = 1, 10 do
winmove.resize_window(win_id, "h", count, winmove.ResizeAnchor.BottomRight)
end

local _, main_col_after, main_width_after, _ = get_win_pos_and_dimensions(win_id)
local _, col_after1, width_after1, _ = get_win_pos_and_dimensions(layout["neighbor1"])
local _, col_after2, width_after2, _ = get_win_pos_and_dimensions(layout["neighbor2"])
local _, col_after3, width_after3, _ = get_win_pos_and_dimensions(layout["neighbor3"])
local _, bottom_col_after, bottom_width_after, _ = get_win_pos_and_dimensions(layout["bottom neighbor"])
local _, col_after4, width_after4, _ = get_win_pos_and_dimensions(layout["neighbor4"])

assert.are.same(vim.api.nvim_win_get_width(layout["neighbor1"]), minwidth_map[layout["neighbor1"]])
assert.are.same(vim.api.nvim_win_get_width(layout["neighbor2"]), minwidth_map[layout["neighbor2"]])
assert.are.same(vim.api.nvim_win_get_width(layout["neighbor3"]), minwidth_map[layout["neighbor3"]])

-- + 3 for the window separators
local left_total_width = minwidth_map[layout["neighbor1"]] + minwidth_map[layout["neighbor2"]] + minwidth_map[layout["neighbor3"]] + 3

assert.are.same(main_col_after, left_total_width)
assert.is._true(main_width_after > main_width_before)

assert.are.same(col_before1, col_after1)
assert.are.same(width_after1, minwidth_map[layout["neighbor1"]])

assert.are.same(col_after2, minwidth_map[layout["neighbor1"]] + 1)
assert.are.same(width_after2, minwidth_map[layout["neighbor2"]])

assert.are.same(col_after3, minwidth_map[layout["neighbor1"]] + minwidth_map[layout["neighbor2"]] + 2)
assert.are.same(width_after3, minwidth_map[layout["neighbor3"]])

-- + 2 for the window separators
local top_column_width = vim.api.nvim_win_get_width(layout["neighbor2"]) + vim.api.nvim_win_get_width(layout["neighbor3"]) + vim.api.nvim_win_get_width(layout["main"]) + 2

assert.are.same(bottom_col_after, vim.api.nvim_win_get_width(layout["neighbor1"]) + 1)
assert.are.same(bottom_width_after, top_column_width)

assert.are.same(col_before4, col_after4)
assert.are.same(width_before4, width_after4)
end)
end)
})

---@type table<integer, integer>
local minwidth_map = {}

for _, _win_id in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
vim.api.nvim_win_call(_win_id, function()
local minwidth = vim.api.nvim_win_get_width(win_id) - count * 3
vim.opt_local.signcolumn = "no"
vim.opt_local.winwidth = minwidth
minwidth_map[_win_id] = minwidth
end)
end

vim.api.nvim_set_current_win(win_id)

local _, _, main_width_before, _ = get_win_pos_and_dimensions(win_id)
local _, col_before1, _, _ = get_win_pos_and_dimensions(layout["neighbor1"])
local _, _, _, _ = get_win_pos_and_dimensions(layout["neighbor2"])
local _, _, _, _ = get_win_pos_and_dimensions(layout["neighbor3"])
local _, _, _, _ = get_win_pos_and_dimensions(layout["bottom neighbor"])
local _, col_before4, width_before4, _ =
get_win_pos_and_dimensions(layout["neighbor4"])

for _ = 1, 10 do
winmove.resize_window(win_id, "h", count, winmove.ResizeAnchor.BottomRight)
end

local _, main_col_after, main_width_after, _ =
get_win_pos_and_dimensions(win_id)
local _, col_after1, width_after1, _ =
get_win_pos_and_dimensions(layout["neighbor1"])
local _, col_after2, width_after2, _ =
get_win_pos_and_dimensions(layout["neighbor2"])
local _, col_after3, width_after3, _ =
get_win_pos_and_dimensions(layout["neighbor3"])
local _, bottom_col_after, bottom_width_after, _ =
get_win_pos_and_dimensions(layout["bottom neighbor"])
local _, col_after4, width_after4, _ =
get_win_pos_and_dimensions(layout["neighbor4"])

assert.are.same(
vim.api.nvim_win_get_width(layout["neighbor1"]),
minwidth_map[layout["neighbor1"]]
)
assert.are.same(
vim.api.nvim_win_get_width(layout["neighbor2"]),
minwidth_map[layout["neighbor2"]]
)
assert.are.same(
vim.api.nvim_win_get_width(layout["neighbor3"]),
minwidth_map[layout["neighbor3"]]
)

-- + 3 for the window separators
local left_total_width = minwidth_map[layout["neighbor1"]]
+ minwidth_map[layout["neighbor2"]]
+ minwidth_map[layout["neighbor3"]]
+ 3

assert.are.same(main_col_after, left_total_width)
assert.is._true(main_width_after > main_width_before)

assert.are.same(col_before1, col_after1)
assert.are.same(width_after1, minwidth_map[layout["neighbor1"]])

assert.are.same(col_after2, minwidth_map[layout["neighbor1"]] + 1)
assert.are.same(width_after2, minwidth_map[layout["neighbor2"]])

assert.are.same(
col_after3,
minwidth_map[layout["neighbor1"]] + minwidth_map[layout["neighbor2"]] + 2
)
assert.are.same(width_after3, minwidth_map[layout["neighbor3"]])

-- + 2 for the window separators
local top_column_width = vim.api.nvim_win_get_width(layout["neighbor2"])
+ vim.api.nvim_win_get_width(layout["neighbor3"])
+ vim.api.nvim_win_get_width(layout["main"])
+ 2

assert.are.same(
bottom_col_after,
vim.api.nvim_win_get_width(layout["neighbor1"]) + 1
)
assert.are.same(bottom_width_after, top_column_width)

assert.are.same(col_before4, col_after4)
assert.are.same(width_before4, width_after4)
end)
end
)
end)
end)

0 comments on commit 50e0a2e

Please sign in to comment.