Add a ready event. (#302)
This commit is contained in:
parent
4271180aea
commit
090697e71f
@ -454,6 +454,14 @@ For example, registering a handler for when a node is renamed is done like this:
|
||||
==============================================================================
|
||||
Lua module: nvim-tree.events *nvim-tree.events*
|
||||
|
||||
*nvim-tree.events.on_nvim_tree_ready()*
|
||||
on_nvim_tree_ready({handler})
|
||||
Registers a handler for when NvimTree has been initialized.
|
||||
|
||||
Parameters: ~
|
||||
{handler} (function) Handler function, with the
|
||||
signature `function()`.
|
||||
|
||||
*nvim-tree.events.on_node_renamed()*
|
||||
on_node_renamed({handler})
|
||||
Registers a handler for when a node is renamed.
|
||||
|
||||
@ -3,6 +3,7 @@ local M = {}
|
||||
local global_handlers = {}
|
||||
|
||||
local Event = {
|
||||
Ready = 'Ready',
|
||||
NodeRenamed = 'NodeRenamed',
|
||||
FileCreated = 'FileCreated',
|
||||
FileRemoved = 'FileRemoved',
|
||||
@ -30,6 +31,11 @@ local function dispatch(event_name, payload)
|
||||
end
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_ready()
|
||||
dispatch(Event.Ready)
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_node_renamed(old_name, new_name)
|
||||
dispatch(Event.NodeRenamed, {old_name=old_name, new_name=new_name})
|
||||
@ -55,6 +61,12 @@ function M._dispatch_folder_removed(folder_name)
|
||||
dispatch(Event.FolderRemoved, {folder_name=folder_name})
|
||||
end
|
||||
|
||||
--Registers a handler for the Ready event.
|
||||
--@param handler (function) Handler with the signature `function()`
|
||||
function M.on_nvim_tree_ready(handler)
|
||||
register_handler(Event.Ready, handler)
|
||||
end
|
||||
|
||||
--Registers a handler for the NodeRenamed event.
|
||||
--@param handler (function) Handler with the signature function(payload), where payload is a table containing:
|
||||
-- - old_name (string) Absolute path to the old node location.
|
||||
|
||||
@ -7,6 +7,7 @@ local git = require'nvim-tree.git'
|
||||
local pops = require'nvim-tree.populate'
|
||||
local utils = require'nvim-tree.utils'
|
||||
local view = require'nvim-tree.view'
|
||||
local events = require'nvim-tree.events'
|
||||
local populate = pops.populate
|
||||
local refresh_entries = pops.refresh_entries
|
||||
|
||||
@ -38,6 +39,8 @@ function M.init(with_open, with_reload)
|
||||
renderer.draw(M.Tree, true)
|
||||
M.Tree.loaded = true
|
||||
end
|
||||
|
||||
events._dispatch_ready()
|
||||
end
|
||||
|
||||
local function get_node_at_line(line)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user