diff --git a/lua/winmove/resize.lua b/lua/winmove/resize.lua index d82951d..70f47ec 100644 --- a/lua/winmove/resize.lua +++ b/lua/winmove/resize.lua @@ -62,7 +62,7 @@ local function adjust_neighbors_in_direction(dir, get_dimension, min_dimension, resize.resize_window, neighbor_win_id, dir, - count, + min_dimension - dimension, anchor ) diff --git a/tests/resize_adjust_neighbors_spec.lua b/tests/resize_adjust_neighbors_spec.lua index 6a67ca8..d0313b6 100644 --- a/tests/resize_adjust_neighbors_spec.lua +++ b/tests/resize_adjust_neighbors_spec.lua @@ -264,29 +264,30 @@ describe("resize", function() }, }) - ---@type table - local minwidth_map = {} + vim.go.winwidth = vim.o.columns / 5 / 2 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) + vim.wo[_win_id].signcolumn = "no" 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 _, col_before1, n1_width_before, _ = + get_win_pos_and_dimensions(layout["neighbor1"]) + local _, _, n2_width_before, _ = get_win_pos_and_dimensions(layout["neighbor2"]) + local _, _, n3_width_before, _ = 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 + local resize_count = n1_width_before + + n2_width_before + + n3_width_before + - (vim.go.winwidth * 3) + + 1 + + for _ = 1, resize_count do winmove.resize_window(win_id, "h", count, winmove.ResizeAnchor.BottomRight) end @@ -305,37 +306,34 @@ describe("resize", function() assert.are.same( vim.api.nvim_win_get_width(layout["neighbor1"]), - minwidth_map[layout["neighbor1"]] + vim.go.winwidth ) assert.are.same( vim.api.nvim_win_get_width(layout["neighbor2"]), - minwidth_map[layout["neighbor2"]] + vim.go.winwidth ) assert.are.same( vim.api.nvim_win_get_width(layout["neighbor3"]), - minwidth_map[layout["neighbor3"]] + vim.go.winwidth ) -- + 3 for the window separators - local left_total_width = minwidth_map[layout["neighbor1"]] - + minwidth_map[layout["neighbor2"]] - + minwidth_map[layout["neighbor3"]] + local left_total_width = vim.api.nvim_win_get_width(layout["neighbor1"]) + + vim.api.nvim_win_get_width(layout["neighbor2"]) + + vim.api.nvim_win_get_width(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(width_after1, vim.go.winwidth) - assert.are.same(col_after2, minwidth_map[layout["neighbor1"]] + 1) - assert.are.same(width_after2, minwidth_map[layout["neighbor2"]]) + assert.are.same(col_after2, vim.go.winwidth + 1) + assert.are.same(width_after2, vim.go.winwidth) - 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_after3, vim.go.winwidth * 2 + 2) + assert.are.same(width_after3, vim.go.winwidth) -- + 2 for the window separators local top_column_width = vim.api.nvim_win_get_width(layout["neighbor2"])