diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 7bf6891c131..dc64044abc2 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -236,6 +236,17 @@ local function setup_autocommands(opts) end, }) end + + -- Handles event dispatch when tree is closed by `:q` + create_nvim_tree_autocmd("WinClosed", { + pattern = "*", + ---@param ev vim.api.keyset.create_autocmd.callback_args + callback = function(ev) + if vim.api.nvim_get_option_value("filetype", { buf = ev.buf }) == "NvimTree" then + require("nvim-tree.events")._dispatch_on_tree_close() + end + end, + }) end local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS diff --git a/lua/nvim-tree/lib.lua b/lua/nvim-tree/lib.lua index abd9d01e229..a464edf39ba 100644 --- a/lua/nvim-tree/lib.lua +++ b/lua/nvim-tree/lib.lua @@ -1,6 +1,5 @@ local view = require("nvim-tree.view") local core = require("nvim-tree.core") -local events = require("nvim-tree.events") local notify = require("nvim-tree.notify") ---@class LibOpenOpts @@ -130,7 +129,6 @@ function M.open(opts) open_view_and_draw() end view.restore_tab_state() - events._dispatch_on_tree_open() end function M.setup(opts) diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index d50efffbcb3..94cf2987dd2 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -254,7 +254,6 @@ local function close(tabpage) return end end - events._dispatch_on_tree_close() return end end @@ -425,6 +424,7 @@ function M.open_in_win(opts) M.reposition_window() M.resize() end + events._dispatch_on_tree_open() end function M.abandon_current_window()