Skip to content

Commit

Permalink
refactor(ui): cleanup maximize code
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Dec 2, 2024
1 parent 9ec253b commit 4a626a8
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lua/lazyvim/util/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit 4a626a8

Please sign in to comment.