fix(zen): properly handle close

This commit is contained in:
Folke Lemaitre 2025-01-20 12:08:52 +01:00
parent ba45c280dd
commit 920a9d28f1
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -181,10 +181,7 @@ function M.zen(opts)
}) })
-- restore toggle states when window is closed -- restore toggle states when window is closed
vim.api.nvim_create_autocmd("WinClosed", { win:on("WinClosed", function()
group = win.augroup,
pattern = tostring(win.win),
callback = vim.schedule_wrap(function()
if zoom_indicator then if zoom_indicator then
zoom_indicator:close() zoom_indicator:close()
end end
@ -192,32 +189,28 @@ function M.zen(opts)
state.toggle:set(state.state) state.toggle:set(state.state)
end end
opts.on_close(win) opts.on_close(win)
end), end, { win = true })
})
-- update the buffer of the parent window -- update the buffer of the parent window
-- when the zen buffer changes -- when the zen buffer changes
vim.api.nvim_create_autocmd("BufWinEnter", { win:on("BufWinEnter", function()
group = win.augroup,
callback = function()
vim.api.nvim_win_set_buf(parent_win, win.buf) vim.api.nvim_win_set_buf(parent_win, win.buf)
end, end, { buf = true })
})
-- close when entering another window -- close when entering another window
vim.api.nvim_create_autocmd("WinEnter", { win:on("WinEnter", function()
group = win.augroup,
callback = function()
local w = vim.api.nvim_get_current_win() local w = vim.api.nvim_get_current_win()
if w == win.win then if w == win.win then
return return
end end
-- exit if other window is not a floating window -- exit if other window is not a floating window
if vim.api.nvim_win_get_config(w).relative == "" then if vim.api.nvim_win_get_config(w).relative == "" then
-- schedule so that WinClosed is properly triggered
vim.schedule(function()
win:close() win:close()
end)
end end
end, end)
})
return win return win
end end