fix: reliably dispatch exactly one TreeOpen and TreeClose events (#3107)
* fix: correctly handle `TreeOpen` and `TreeClose` event dispatch * fix: lint issues
This commit is contained in:
parent
5bea2b3752
commit
3a63717d3d
@ -236,6 +236,17 @@ local function setup_autocommands(opts)
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
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
|
end
|
||||||
|
|
||||||
local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
local view = require("nvim-tree.view")
|
local view = require("nvim-tree.view")
|
||||||
local core = require("nvim-tree.core")
|
local core = require("nvim-tree.core")
|
||||||
local events = require("nvim-tree.events")
|
|
||||||
local notify = require("nvim-tree.notify")
|
local notify = require("nvim-tree.notify")
|
||||||
|
|
||||||
---@class LibOpenOpts
|
---@class LibOpenOpts
|
||||||
@ -130,7 +129,6 @@ function M.open(opts)
|
|||||||
open_view_and_draw()
|
open_view_and_draw()
|
||||||
end
|
end
|
||||||
view.restore_tab_state()
|
view.restore_tab_state()
|
||||||
events._dispatch_on_tree_open()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
|
|||||||
@ -254,7 +254,6 @@ local function close(tabpage)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
events._dispatch_on_tree_close()
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -425,6 +424,7 @@ function M.open_in_win(opts)
|
|||||||
M.reposition_window()
|
M.reposition_window()
|
||||||
M.resize()
|
M.resize()
|
||||||
end
|
end
|
||||||
|
events._dispatch_on_tree_open()
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.abandon_current_window()
|
function M.abandon_current_window()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user