Skip to content

Commit 18de5bb

Browse files
committed
fix(win): properly handle closing the last window. Fixes #793
1 parent 8ed0e5d commit 18de5bb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lua/snacks/win.lua

+8-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,14 @@ function M:close(opts)
518518

519519
local close = function()
520520
if win and vim.api.nvim_win_is_valid(win) then
521-
vim.api.nvim_win_close(win, true)
521+
local ok, err = pcall(vim.api.nvim_win_close, win, true)
522+
if not ok and (err and err:find("E444")) then
523+
-- last window, so creat a split and close it again
524+
vim.cmd("silent! vsplit")
525+
pcall(vim.api.nvim_win_close, win, true)
526+
elseif not ok then
527+
error(err)
528+
end
522529
end
523530
if buf and vim.api.nvim_buf_is_valid(buf) then
524531
vim.api.nvim_buf_delete(buf, { force = true })

0 commit comments

Comments
 (0)