Skip to content
Open
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
16 changes: 16 additions & 0 deletions lua/winshift/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,21 @@ function M.find_leaf(tree, winid)
return recurse(tree)
end

local function get_window_dimensions(winid)
return { width = api.nvim_win_get_width(winid), height = api.nvim_win_get_height(winid) }
end

local function set_window_dimensions(winid, dimensions)
api.nvim_win_set_width(winid, dimensions.width)
api.nvim_win_set_height(winid, dimensions.height)
end

---@param a Node
---@param b Node
function M.swap_leaves(a, b)
local dimensions_a = get_window_dimensions(a.winid)
local dimensions_b = get_window_dimensions(b.winid)

vim.cmd(
string.format(
"noautocmd keepjumps %dwindo belowright %s",
Expand All @@ -115,8 +127,12 @@ function M.swap_leaves(a, b)

vim.fn.win_splitmove(a.winid, temp_b, opt_b)
vim.fn.win_splitmove(b.winid, temp_a, opt_a)

api.nvim_win_close(temp_a, true)
api.nvim_win_close(temp_b, true)

set_window_dimensions(a.winid, dimensions_b)
set_window_dimensions(b.winid, dimensions_a)
end

---Move a row into a target window, replacing the target.
Expand Down