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: remove unnecessary uses of nvim_win_call #127

Merged
merged 2 commits into from
Sep 6, 2023
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
11 changes: 4 additions & 7 deletions lua/focus/modules/resizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down
38 changes: 38 additions & 0 deletions tests/test_autoresize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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