refactor(ui): cleanup maximize code

This commit is contained in:
Folke Lemaitre
2024-12-02 23:46:11 +01:00
parent 9ec253b9b6
commit 4a626a8137

View File

@ -34,8 +34,7 @@ end
function M.maximize()
---@type {k:string, v:any}[]?
local maximized = nil
local ret
ret = Snacks.toggle({
local toggle = Snacks.toggle({
name = "Maximize",
get = function()
return maximized ~= nil
@ -52,15 +51,6 @@ function M.maximize()
set("winminwidth", 10)
set("winminheight", 4)
vim.cmd("wincmd =")
-- `QuitPre` seems to be executed even if we quit a normal window, so we don't want that
-- `VimLeavePre` might be another consideration? Not sure about differences between the 2
vim.api.nvim_create_autocmd("ExitPre", {
group = vim.api.nvim_create_augroup("lazyvim_restore_max_exit_pre", { clear = true }),
desc = "Restore width/height when close Neovim while maximized",
callback = function()
ret:set(false)
end,
})
else
for _, opt in ipairs(maximized) do
vim.o[opt.k] = opt.v
@ -70,7 +60,19 @@ function M.maximize()
end
end,
})
return ret
-- `QuitPre` seems to be executed even if we quit a normal window, so we don't want that
-- `VimLeavePre` might be another consideration? Not sure about differences between the 2
vim.api.nvim_create_autocmd("ExitPre", {
group = vim.api.nvim_create_augroup("lazyvim_restore_max_exit_pre", { clear = true }),
desc = "Restore width/height when close Neovim while maximized",
callback = function()
if toggle:get() then
toggle:set(false)
end
end,
})
return toggle
end
return M