feat - add open and close tree events (#1151)
This commit is contained in:
parent
ff6ef58b03
commit
cff5a106b2
@ -988,6 +988,22 @@ on_folder_created({handler})
|
||||
on_folder_removed({handler})
|
||||
Registers a handler for when a folder is removed.
|
||||
|
||||
Parameters: ~
|
||||
{handler} (function) Handler function, with the
|
||||
signature `function(payload)`.
|
||||
|
||||
*nvim-tree.events.on_tree_open()*
|
||||
on_tree_open({handler})
|
||||
Registers a handler for when NvimTree is opened.
|
||||
|
||||
Parameters: ~
|
||||
{handler} (function) Handler function, with the
|
||||
signature `function(payload)`.
|
||||
|
||||
*nvim-tree.events.on_tree_close()*
|
||||
on_tree_close({handler})
|
||||
Registers a handler for when NvimTree is closed.
|
||||
|
||||
Parameters: ~
|
||||
{handler} (function) Handler function, with the
|
||||
signature `function(payload)`.
|
||||
|
||||
@ -5,6 +5,8 @@ local global_handlers = {}
|
||||
local Event = {
|
||||
Ready = "Ready",
|
||||
NodeRenamed = "NodeRenamed",
|
||||
TreeOpen = "TreeOpen",
|
||||
TreeClose = "TreeClose",
|
||||
FileCreated = "FileCreated",
|
||||
FileRemoved = "FileRemoved",
|
||||
FolderCreated = "FolderCreated",
|
||||
@ -60,6 +62,16 @@ function M._dispatch_folder_removed(folder_name)
|
||||
dispatch(Event.FolderRemoved, { folder_name = folder_name })
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_on_tree_open()
|
||||
dispatch(Event.TreeOpen, nil)
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_on_tree_close()
|
||||
dispatch(Event.TreeClose, nil)
|
||||
end
|
||||
|
||||
--Registers a handler for the Ready event.
|
||||
--@param handler (function) Handler with the signature `function()`
|
||||
function M.on_nvim_tree_ready(handler)
|
||||
@ -102,4 +114,16 @@ function M.on_folder_removed(handler)
|
||||
register_handler(Event.FolderRemoved, handler)
|
||||
end
|
||||
|
||||
--Registers a handler for the TreeOpen event.
|
||||
--@param handler (function) Handler with the signature function(payload)
|
||||
function M.on_tree_open(handler)
|
||||
register_handler(Event.TreeOpen, handler)
|
||||
end
|
||||
|
||||
--Registers a handler for the TreeClose event.
|
||||
--@param handler (function) Handler with the signature function(payload)
|
||||
function M.on_tree_close(handler)
|
||||
register_handler(Event.TreeClose, handler)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@ -2,6 +2,8 @@ local a = vim.api
|
||||
|
||||
local M = {}
|
||||
|
||||
local events = require "nvim-tree.events"
|
||||
|
||||
M.View = {
|
||||
tabpages = {},
|
||||
hide_root_folder = false,
|
||||
@ -173,6 +175,7 @@ function M.close()
|
||||
if tree_win == current_win and LAST_FOCUSED_WIN then
|
||||
a.nvim_set_current_win(LAST_FOCUSED_WIN)
|
||||
end
|
||||
events._dispatch_on_tree_close()
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -193,6 +196,7 @@ function M.open(options)
|
||||
if not opts.focus_tree then
|
||||
vim.cmd "wincmd p"
|
||||
end
|
||||
events._dispatch_on_tree_open()
|
||||
end
|
||||
|
||||
function M.resize(size)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user