Skip to content

Commit 27caccb

Browse files
committed
fix: switch buffers on close
when closing the tree which is the last window, switches buffers instead of getting an input with a message to close nvim or ignore.
1 parent b1c4479 commit 27caccb

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lua/nvim-tree/view.lua

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,17 @@ end
322322
function M.close()
323323
if not M.win_open() then return end
324324
if #a.nvim_list_wins() == 1 then
325-
local ans = vim.fn.input(
326-
'[NvimTree] this is the last open window, are you sure you want to quit nvim ? y/n: '
325+
local ok_bufs = vim.tbl_filter(
326+
function(buf)
327+
return a.nvim_buf_is_valid(buf) and vim.fn.buflisted(buf) == 1
328+
end,
329+
a.nvim_list_bufs()
327330
)
328-
if ans == 'y' then
329-
vim.cmd "q!"
331+
if #ok_bufs > 0 then
332+
vim.cmd "sbnext"
333+
else
334+
vim.cmd "new"
330335
end
331-
return
332336
end
333337
a.nvim_win_hide(M.get_winnr())
334338
end

0 commit comments

Comments
 (0)