Skip to content

Commit bd48816

Browse files
fix: safely close last tree window (#2913)
fix: safely close tree window with pcall and debug logging Co-authored-by: Alexander Courtis <[email protected]>
1 parent cd9c6db commit bd48816

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

doc/nvim-tree-lua.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,7 @@ Specify minimum notification level, uses the values from |vim.log.levels|
15761576
`ERROR`: hard errors e.g. failure to read from the file system.
15771577
`WARNING`: non-fatal errors e.g. unable to system open a file.
15781578
`INFO:` information only e.g. file copy path confirmation.
1579-
`DEBUG:` not used.
1579+
`DEBUG:` information for troubleshooting, e.g. failures in some window closing operations.
15801580

15811581
*nvim-tree.notify.absolute_path*
15821582
Whether to use absolute paths or item names in fs action notifications.

lua/nvim-tree/view.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local events = require "nvim-tree.events"
22
local utils = require "nvim-tree.utils"
33
local log = require "nvim-tree.log"
4+
local notify = require "nvim-tree.notify"
45

56
---@class OpenInWinOpts
67
---@field hijack_current_buf boolean|nil default true
@@ -227,7 +228,11 @@ local function close(tabpage)
227228
vim.api.nvim_set_current_win(vim.fn.win_getid(prev_win))
228229
end
229230
if vim.api.nvim_win_is_valid(tree_win or 0) then
230-
vim.api.nvim_win_close(tree_win or 0, true)
231+
local success, error = pcall(vim.api.nvim_win_close, tree_win or 0, true)
232+
if not success then
233+
notify.debug("Failed to close window: " .. error)
234+
return
235+
end
231236
end
232237
events._dispatch_on_tree_close()
233238
return

0 commit comments

Comments
 (0)