Skip to content

Commit 3a63717

Browse files
authored
fix: reliably dispatch exactly one TreeOpen and TreeClose events (#3107)
* fix: correctly handle `TreeOpen` and `TreeClose` event dispatch * fix: lint issues
1 parent 5bea2b3 commit 3a63717

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

Diff for: lua/nvim-tree.lua

+11
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,17 @@ local function setup_autocommands(opts)
236236
end,
237237
})
238238
end
239+
240+
-- Handles event dispatch when tree is closed by `:q`
241+
create_nvim_tree_autocmd("WinClosed", {
242+
pattern = "*",
243+
---@param ev vim.api.keyset.create_autocmd.callback_args
244+
callback = function(ev)
245+
if vim.api.nvim_get_option_value("filetype", { buf = ev.buf }) == "NvimTree" then
246+
require("nvim-tree.events")._dispatch_on_tree_close()
247+
end
248+
end,
249+
})
239250
end
240251

241252
local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS

Diff for: lua/nvim-tree/lib.lua

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
local view = require("nvim-tree.view")
22
local core = require("nvim-tree.core")
3-
local events = require("nvim-tree.events")
43
local notify = require("nvim-tree.notify")
54

65
---@class LibOpenOpts
@@ -130,7 +129,6 @@ function M.open(opts)
130129
open_view_and_draw()
131130
end
132131
view.restore_tab_state()
133-
events._dispatch_on_tree_open()
134132
end
135133

136134
function M.setup(opts)

Diff for: lua/nvim-tree/view.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ local function close(tabpage)
254254
return
255255
end
256256
end
257-
events._dispatch_on_tree_close()
258257
return
259258
end
260259
end
@@ -425,6 +424,7 @@ function M.open_in_win(opts)
425424
M.reposition_window()
426425
M.resize()
427426
end
427+
events._dispatch_on_tree_open()
428428
end
429429

430430
function M.abandon_current_window()

0 commit comments

Comments
 (0)