From 8b13211bca36651a0a09ed07f4cf2bfb9836b8a4 Mon Sep 17 00:00:00 2001 From: Will Hopkins Date: Thu, 24 Aug 2023 12:31:24 -0700 Subject: [PATCH 1/2] fix: remove unnecessary uses of nvim_win_call --- lua/focus/modules/resizer.lua | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lua/focus/modules/resizer.lua b/lua/focus/modules/resizer.lua index b2d5cae..1c47440 100644 --- a/lua/focus/modules/resizer.lua +++ b/lua/focus/modules/resizer.lua @@ -71,14 +71,15 @@ function M.maximise() local view = vim.fn.winsaveview() vim.api.nvim_win_set_width(win, width) vim.api.nvim_win_set_height(win, height) - vim.api.nvim_win_call(function() - vim.fn.winrestview(view) - end) + vim.fn.winrestview(view) end M.goal = 'autoresize' function M.split_resizer(config, goal) --> Only resize normal buffers, set qf to 10 always + if goal then + M.goal = goal + end if utils.is_disabled() or vim.api.nvim_win_get_option(0, 'diff') @@ -105,10 +106,6 @@ function M.split_resizer(config, goal) --> Only resize normal buffers, set qf to end end - if goal then - M.goal = goal - end - if vim.bo.filetype == 'qf' and config.autoresize.height_quickfix > 0 then vim.api.nvim_win_set_height(0, config.autoresize.height_quickfix) return From 4cde6407278495a5683b3965325e36e11ae68f5e Mon Sep 17 00:00:00 2001 From: Will Hopkins Date: Tue, 5 Sep 2023 20:47:27 -0700 Subject: [PATCH 2/2] test: add tests for maximize --- tests/test_autoresize.lua | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/test_autoresize.lua b/tests/test_autoresize.lua index 9a4c13a..2ce8aa2 100644 --- a/tests/test_autoresize.lua +++ b/tests/test_autoresize.lua @@ -241,4 +241,42 @@ T['autoresize']['terminal'] = function() child.cmd('wincmd w') end +T['autoresize']['maximize'] = function() + reload_module({ autoresize = {} }) + child.cmd('vsplit') + child.cmd('FocusMaximise') + + local resize_state = child.get_resize_state() + local win_id_left = resize_state.windows[1] + local win_id_right = resize_state.windows[2] + + -- we should be in the left win + eq(win_id_left, child.api.nvim_get_current_win()) + + -- let should take up the entire width, other than the winseparator (1 col) + -- and numbercolumn (1 col) + validate_win_dims(win_id_left, { 78, 23 }) + validate_win_dims(win_id_right, { 1, 23 }) +end + +T['autoresize']['maximize_minwidth'] = function() + reload_module({ autoresize = { + minwidth = 12, + } }) + child.cmd('vsplit') + child.cmd('FocusMaximise') + + local resize_state = child.get_resize_state() + local win_id_left = resize_state.windows[1] + local win_id_right = resize_state.windows[2] + + -- we should be in the left win + eq(win_id_left, child.api.nvim_get_current_win()) + + -- let should take up the entire width, other than the winseparator (1 col) + -- and numbercolumn (1 col) + validate_win_dims(win_id_left, { 67, 23 }) + validate_win_dims(win_id_right, { 12, 23 }) +end + return T