mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-05 03:08:13 +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
|
-- restore toggle states when window is closed
|
||||||
vim.api.nvim_create_autocmd("WinClosed", {
|
win:on("WinClosed", function()
|
||||||
group = win.augroup,
|
if zoom_indicator then
|
||||||
pattern = tostring(win.win),
|
zoom_indicator:close()
|
||||||
callback = vim.schedule_wrap(function()
|
end
|
||||||
if zoom_indicator then
|
for _, state in ipairs(states) do
|
||||||
zoom_indicator:close()
|
state.toggle:set(state.state)
|
||||||
end
|
end
|
||||||
for _, state in ipairs(states) do
|
opts.on_close(win)
|
||||||
state.toggle:set(state.state)
|
end, { win = true })
|
||||||
end
|
|
||||||
opts.on_close(win)
|
|
||||||
end),
|
|
||||||
})
|
|
||||||
|
|
||||||
-- 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,
|
vim.api.nvim_win_set_buf(parent_win, win.buf)
|
||||||
callback = function()
|
end, { buf = true })
|
||||||
vim.api.nvim_win_set_buf(parent_win, win.buf)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
-- close when entering another window
|
-- close when entering another window
|
||||||
vim.api.nvim_create_autocmd("WinEnter", {
|
win:on("WinEnter", function()
|
||||||
group = win.augroup,
|
local w = vim.api.nvim_get_current_win()
|
||||||
callback = function()
|
if w == win.win then
|
||||||
local w = vim.api.nvim_get_current_win()
|
return
|
||||||
if w == win.win then
|
end
|
||||||
return
|
-- exit if other window is not a floating window
|
||||||
end
|
if vim.api.nvim_win_get_config(w).relative == "" then
|
||||||
-- exit if other window is not a floating window
|
-- schedule so that WinClosed is properly triggered
|
||||||
if vim.api.nvim_win_get_config(w).relative == "" then
|
vim.schedule(function()
|
||||||
win:close()
|
win:close()
|
||||||
end
|
end)
|
||||||
end,
|
end
|
||||||
})
|
end)
|
||||||
return win
|
return win
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue