Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 9 additions & 4 deletions lua/focus/modules/resizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ local golden_ratio_minheight = function()
return math.floor(golden_ratio_height() / (3 * golden_ratio))
end

local function save_fixed_win_dims()
local function save_fixed_win_dims(config)
local fixed_dims = {}
local height_quickfix = config and config.autoresize.height_quickfix or 0

for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
if vim.api.nvim_win_get_config(win).zindex == nil then
Expand All @@ -32,6 +33,8 @@ local function save_fixed_win_dims()
width = vim.api.nvim_win_get_width(win),
height = vim.api.nvim_win_get_height(win),
}
elseif height_quickfix > 0 and vim.bo[buf].filetype == 'qf' then
fixed_dims[win] = { height = height_quickfix }
end
end
end
Expand All @@ -42,7 +45,9 @@ 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)
if dims.width then
vim.api.nvim_win_set_width(win, dims.width)
end
vim.api.nvim_win_set_height(win, dims.height)
end
end
Expand Down Expand Up @@ -74,7 +79,7 @@ function M.autoresize(config)
-- If equalise mode, just equalize all windows and return
if should_equalise then
local cmdheight = vim.o.cmdheight
local fixed = save_fixed_win_dims()
local fixed = save_fixed_win_dims(config)
vim.api.nvim_exec2('wincmd =', { output = false })
restore_fixed_win_dims(fixed)
vim.o.cmdheight = cmdheight
Expand Down Expand Up @@ -117,7 +122,7 @@ 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()
local fixed = save_fixed_win_dims(config)

vim.api.nvim_win_set_width(0, width)
vim.api.nvim_win_set_height(0, height)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_autoresize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,22 @@ T['autoresize']['quickfix'] = function()
validate_win_dims(win_id_lower, { 80, 10 })
end

T['autoresize']['quickfix keeps height_quickfix when focus leaves'] = function()
reload_module({ autoresize = { height_quickfix = 5 } })
child.cmd('vimgrep /ipsum/' .. lorem_ipsum_file)
child.cmd('copen')

local resize_state = child.get_resize_state()
local win_id_upper = resize_state.windows[1]
local win_id_lower = resize_state.windows[2]

-- Moving focus to the upper window resizes it; the quickfix window must
-- keep its configured height.
child.api.nvim_set_current_win(win_id_upper)

eq(child.api.nvim_win_get_height(win_id_lower), 5)
end

T['autoresize']['terminal'] = function()
-- create a new term split
child.cmd('split')
Expand Down
Loading