Skip to content

Commit

Permalink
Finish tests for adjusting neighbors
Browse files Browse the repository at this point in the history
  • Loading branch information
MisanthropicBit committed May 26, 2024
1 parent e266619 commit 218718e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
8 changes: 6 additions & 2 deletions lua/winmove/resize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ local function can_resize(dir, get_dimension_func, min_dimension)
return neighbor_count ~= applied
end

--- Adjust right-hand side neighbors when using a bottom-right corner
--- Adjust right-hand side sibling neighbors when using a bottom-right corner
---@param win_id integer
---@param rev_dir winmove.Direction
---@param count integer
Expand All @@ -76,6 +76,8 @@ local function adjust_neighbors_bottom_right_anchor(win_id, rev_dir, count)
resize.anchor.BottomRight,
true
)
else
return false, false
end

return true, true
Expand Down Expand Up @@ -104,6 +106,8 @@ local function adjust_neighbors_in_direction(dir, get_dimension, get_min_dimensi
nil
)

vim.api.nvim_win_set_width(neighbor_win_id, min_dimension)

return true, true
end

Expand Down Expand Up @@ -199,7 +203,7 @@ function resize.resize_window(win_id, dir, count, anchor, ignore_neighbors)
-- To compensate, we resize the opposite neighbor in the other
-- direction with an opposite anchor. This is only relevant when
-- using the bottom-right corner
if not ignore_neighbors and not top_left then -- and dir ~= "l" then
if not ignore_neighbors and not top_left then
local rev_dir = winutil.reverse_direction(dir)

-- For a bottom-right anchor, always resize neighbors on the right since we
Expand Down
37 changes: 22 additions & 15 deletions tests/resize_adjust_neighbors_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -247,19 +247,20 @@ describe("resize", function()

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
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_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 _, _, 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
Expand All @@ -277,20 +278,26 @@ describe("resize", function()
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"]])

-- assert.are.same(main_col_before - count, main_col_after)
-- assert.are.same(main_width_before + count, main_width_after)
-- + 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_before1, width_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_before2, col_after2)
-- assert.are.same(width_before2, width_after2)
assert.are.same(col_after3, minwidth_map[layout["neighbor1"]] + minwidth_map[layout["neighbor2"]] + 2)
assert.are.same(width_after3, minwidth_map[layout["neighbor3"]])

-- assert.are.same(col_before3, col_after3)
-- assert.are.same(width_before3 - count, width_after3)
-- + 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_before, bottom_col_after)
-- assert.are.same(bottom_width_before, bottom_width_after)
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)
Expand Down

0 comments on commit 218718e

Please sign in to comment.