Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: save and restore fixed win dimensions on resize #136

Merged
merged 1 commit into from
Oct 5, 2023
Merged
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
40 changes: 37 additions & 3 deletions lua/focus/modules/resizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,33 @@ local golden_ratio_minheight = function()
return math.floor(golden_ratio_height() / (3 * golden_ratio))
end

local function save_fixed_win_dims()
local fixed_dims = {}

for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
if vim.api.nvim_win_get_config(win).zindex == nil then
local buf = vim.api.nvim_win_get_buf(win)
if vim.w[win].focus_disable or vim.b[buf].focus_disable then
fixed_dims[win] = {
width = vim.api.nvim_win_get_width(win),
height = vim.api.nvim_win_get_height(win),
}
end
end
end

return fixed_dims
end

local function restore_fixed_win_dims(fixed_dims)
for win, dims in pairs(fixed_dims) do
if vim.api.nvim_win_is_valid(win) then
vim.api.nvim_win_set_width(win, dims.width)
vim.api.nvim_win_set_height(win, dims.height)
end
end
end

function M.autoresize(config)
local width
if config.autoresize.width > 0 then
Expand Down Expand Up @@ -49,9 +76,13 @@ function M.autoresize(config)
-- save cmdheight to ensure it is not changed by nvim_win_set_height
local cmdheight = vim.o.cmdheight

local fixed = save_fixed_win_dims()

vim.api.nvim_win_set_width(0, width)
vim.api.nvim_win_set_height(0, height)

restore_fixed_win_dims(fixed)

vim.o.cmdheight = cmdheight
end

Expand All @@ -62,9 +93,12 @@ end
function M.maximise()
local width, height = vim.o.columns, vim.o.lines

local win = vim.api.nvim_get_current_win()
vim.api.nvim_win_set_width(win, width)
vim.api.nvim_win_set_height(win, height)
local fixed = save_fixed_win_dims()

vim.api.nvim_win_set_width(0, width)
vim.api.nvim_win_set_height(0, height)

restore_fixed_win_dims(fixed)
end

M.goal = 'autoresize'
Expand Down