feat(event): add TreeRendered (#2324)

* add TreeRendered event

* pass bufnr and winnr to TreeRendered event

---------

Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
Stefano Stoduto
2023-07-16 09:22:45 +02:00
committed by GitHub
parent 697bfaccac
commit 3b62c6bf2c
3 changed files with 18 additions and 0 deletions

View File

@@ -2235,6 +2235,15 @@ e.g. handler for node renamed: >
handler parameters: ~ handler parameters: ~
{buf} `{number} `API buffer handle (buffer number) {buf} `{number} `API buffer handle (buffer number)
- Event.TreeRendered
Invoked every time the tree is redrawn. Normally this event
happens after |Event.TreeOpen| except that handlers of this
one will have access to the tree buffer populated with the
final content.
handler parameters: ~
{bufnr} `{number} `API buffer handle (buffer number)
{winnr} `{number} `API window handle (window number)
|nvim_tree_events_startup| |nvim_tree_events_startup|
There are two special startup events in the form of User autocommands: There are two special startup events in the form of User autocommands:

View File

@@ -18,6 +18,7 @@ M.Event = {
FolderRemoved = "FolderRemoved", FolderRemoved = "FolderRemoved",
Resize = "Resize", Resize = "Resize",
TreeAttachedPost = "TreeAttachedPost", TreeAttachedPost = "TreeAttachedPost",
TreeRendered = "TreeRendered",
} }
local function get_handlers(event_name) local function get_handlers(event_name)
@@ -104,4 +105,9 @@ function M._dispatch_tree_attached_post(buf)
dispatch(M.Event.TreeAttachedPost, buf) dispatch(M.Event.TreeAttachedPost, buf)
end end
--@private
function M._dispatch_on_tree_rendered(bufnr, winnr)
dispatch(M.Event.TreeRendered, { bufnr = bufnr, winnr = winnr })
end
return M return M

View File

@@ -2,6 +2,7 @@ local core = require "nvim-tree.core"
local diagnostics = require "nvim-tree.diagnostics" local diagnostics = require "nvim-tree.diagnostics"
local log = require "nvim-tree.log" local log = require "nvim-tree.log"
local view = require "nvim-tree.view" local view = require "nvim-tree.view"
local events = require "nvim-tree.events"
local modified = require "nvim-tree.renderer.components.modified" local modified = require "nvim-tree.renderer.components.modified"
local _padding = require "nvim-tree.renderer.components.padding" local _padding = require "nvim-tree.renderer.components.padding"
@@ -89,6 +90,8 @@ function M.draw(unloaded_bufnr)
view.grow_from_content() view.grow_from_content()
log.profile_end(profile) log.profile_end(profile)
events._dispatch_on_tree_rendered(bufnr, view.get_winnr())
end end
function M.setup(opts) function M.setup(opts)