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*
|
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()*
|
*nvim-tree.events.on_node_renamed()*
|
||||||
on_node_renamed({handler})
|
on_node_renamed({handler})
|
||||||
Registers a handler for when a node is renamed.
|
Registers a handler for when a node is renamed.
|
||||||
|
|||||||
@ -3,6 +3,7 @@ local M = {}
|
|||||||
local global_handlers = {}
|
local global_handlers = {}
|
||||||
|
|
||||||
local Event = {
|
local Event = {
|
||||||
|
Ready = 'Ready',
|
||||||
NodeRenamed = 'NodeRenamed',
|
NodeRenamed = 'NodeRenamed',
|
||||||
FileCreated = 'FileCreated',
|
FileCreated = 'FileCreated',
|
||||||
FileRemoved = 'FileRemoved',
|
FileRemoved = 'FileRemoved',
|
||||||
@ -30,6 +31,11 @@ local function dispatch(event_name, payload)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--@private
|
||||||
|
function M._dispatch_ready()
|
||||||
|
dispatch(Event.Ready)
|
||||||
|
end
|
||||||
|
|
||||||
--@private
|
--@private
|
||||||
function M._dispatch_node_renamed(old_name, new_name)
|
function M._dispatch_node_renamed(old_name, new_name)
|
||||||
dispatch(Event.NodeRenamed, {old_name=old_name, new_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})
|
dispatch(Event.FolderRemoved, {folder_name=folder_name})
|
||||||
end
|
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.
|
--Registers a handler for the NodeRenamed event.
|
||||||
--@param handler (function) Handler with the signature function(payload), where payload is a table containing:
|
--@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.
|
-- - 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 pops = require'nvim-tree.populate'
|
||||||
local utils = require'nvim-tree.utils'
|
local utils = require'nvim-tree.utils'
|
||||||
local view = require'nvim-tree.view'
|
local view = require'nvim-tree.view'
|
||||||
|
local events = require'nvim-tree.events'
|
||||||
local populate = pops.populate
|
local populate = pops.populate
|
||||||
local refresh_entries = pops.refresh_entries
|
local refresh_entries = pops.refresh_entries
|
||||||
|
|
||||||
@ -38,6 +39,8 @@ function M.init(with_open, with_reload)
|
|||||||
renderer.draw(M.Tree, true)
|
renderer.draw(M.Tree, true)
|
||||||
M.Tree.loaded = true
|
M.Tree.loaded = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
events._dispatch_ready()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_node_at_line(line)
|
local function get_node_at_line(line)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user