mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 10:49:08 +00:00
fix(zen): properly handle close
This commit is contained in:
parent
ba45c280dd
commit
920a9d28f1
1 changed files with 24 additions and 31 deletions
|
@ -181,43 +181,36 @@ function M.zen(opts)
|
|||
})
|
||||
|
||||
-- restore toggle states when window is closed
|
||||
vim.api.nvim_create_autocmd("WinClosed", {
|
||||
group = win.augroup,
|
||||
pattern = tostring(win.win),
|
||||
callback = vim.schedule_wrap(function()
|
||||
if zoom_indicator then
|
||||
zoom_indicator:close()
|
||||
end
|
||||
for _, state in ipairs(states) do
|
||||
state.toggle:set(state.state)
|
||||
end
|
||||
opts.on_close(win)
|
||||
end),
|
||||
})
|
||||
win:on("WinClosed", function()
|
||||
if zoom_indicator then
|
||||
zoom_indicator:close()
|
||||
end
|
||||
for _, state in ipairs(states) do
|
||||
state.toggle:set(state.state)
|
||||
end
|
||||
opts.on_close(win)
|
||||
end, { win = true })
|
||||
|
||||
-- update the buffer of the parent window
|
||||
-- when the zen buffer changes
|
||||
vim.api.nvim_create_autocmd("BufWinEnter", {
|
||||
group = win.augroup,
|
||||
callback = function()
|
||||
vim.api.nvim_win_set_buf(parent_win, win.buf)
|
||||
end,
|
||||
})
|
||||
win:on("BufWinEnter", function()
|
||||
vim.api.nvim_win_set_buf(parent_win, win.buf)
|
||||
end, { buf = true })
|
||||
|
||||
-- close when entering another window
|
||||
vim.api.nvim_create_autocmd("WinEnter", {
|
||||
group = win.augroup,
|
||||
callback = function()
|
||||
local w = vim.api.nvim_get_current_win()
|
||||
if w == win.win then
|
||||
return
|
||||
end
|
||||
-- exit if other window is not a floating window
|
||||
if vim.api.nvim_win_get_config(w).relative == "" then
|
||||
win:on("WinEnter", function()
|
||||
local w = vim.api.nvim_get_current_win()
|
||||
if w == win.win then
|
||||
return
|
||||
end
|
||||
-- exit if other window is not a floating window
|
||||
if vim.api.nvim_win_get_config(w).relative == "" then
|
||||
-- schedule so that WinClosed is properly triggered
|
||||
vim.schedule(function()
|
||||
win:close()
|
||||
end
|
||||
end,
|
||||
})
|
||||
end)
|
||||
end
|
||||
end)
|
||||
return win
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue