From a17ea63770a7a6bf73eb1bb3c9d491bea42a327e Mon Sep 17 00:00:00 2001 From: beauwilliams Date: Sun, 15 Nov 2026 09:52:42 +1100 Subject: [PATCH] fix(resizer): keep height_quickfix when focus leaves the quickfix window The quickfix height was only applied while the quickfix window was focused. Resizing the newly focused window then changed the quickfix height. Treat quickfix windows as fixed-height during autoresize. Fixes #179 --- lua/focus/modules/resizer.lua | 13 +++++++++---- tests/test_autoresize.lua | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lua/focus/modules/resizer.lua b/lua/focus/modules/resizer.lua index 03cd7ea..0a7213d 100644 --- a/lua/focus/modules/resizer.lua +++ b/lua/focus/modules/resizer.lua @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) diff --git a/tests/test_autoresize.lua b/tests/test_autoresize.lua index 6b3a84e..45301b1 100644 --- a/tests/test_autoresize.lua +++ b/tests/test_autoresize.lua @@ -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')