Skip to content

fix: safely close last tree window #2913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ Specify minimum notification level, uses the values from |vim.log.levels|
`ERROR`: hard errors e.g. failure to read from the file system.
`WARNING`: non-fatal errors e.g. unable to system open a file.
`INFO:` information only e.g. file copy path confirmation.
`DEBUG:` not used.
`DEBUG:` information for troubleshooting, e.g. failures in some window closing operations.

*nvim-tree.notify.absolute_path*
Whether to use absolute paths or item names in fs action notifications.
Expand Down
7 changes: 6 additions & 1 deletion lua/nvim-tree/view.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local events = require "nvim-tree.events"
local utils = require "nvim-tree.utils"
local log = require "nvim-tree.log"
local notify = require "nvim-tree.notify"

---@class OpenInWinOpts
---@field hijack_current_buf boolean|nil default true
Expand Down Expand Up @@ -227,7 +228,11 @@ local function close(tabpage)
vim.api.nvim_set_current_win(vim.fn.win_getid(prev_win))
end
if vim.api.nvim_win_is_valid(tree_win or 0) then
vim.api.nvim_win_close(tree_win or 0, true)
local success, error = pcall(vim.api.nvim_win_close, tree_win or 0, true)
if not success then
notify.debug("Failed to close window: " .. error)
return
end
end
events._dispatch_on_tree_close()
return
Expand Down
Loading