Skip to content

feat(event): add TreeRendered #2324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2235,6 +2235,15 @@ e.g. handler for node renamed: >
handler parameters: ~
{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|

There are two special startup events in the form of User autocommands:
Expand Down
6 changes: 6 additions & 0 deletions lua/nvim-tree/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ M.Event = {
FolderRemoved = "FolderRemoved",
Resize = "Resize",
TreeAttachedPost = "TreeAttachedPost",
TreeRendered = "TreeRendered",
}

local function get_handlers(event_name)
Expand Down Expand Up @@ -104,4 +105,9 @@ function M._dispatch_tree_attached_post(buf)
dispatch(M.Event.TreeAttachedPost, buf)
end

--@private
function M._dispatch_on_tree_rendered(bufnr, winnr)
dispatch(M.Event.TreeRendered, { bufnr = bufnr, winnr = winnr })
end

return M
3 changes: 3 additions & 0 deletions lua/nvim-tree/renderer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local core = require "nvim-tree.core"
local diagnostics = require "nvim-tree.diagnostics"
local log = require "nvim-tree.log"
local view = require "nvim-tree.view"
local events = require "nvim-tree.events"
local modified = require "nvim-tree.renderer.components.modified"

local _padding = require "nvim-tree.renderer.components.padding"
Expand Down Expand Up @@ -89,6 +90,8 @@ function M.draw(unloaded_bufnr)
view.grow_from_content()

log.profile_end(profile)

events._dispatch_on_tree_rendered(bufnr, view.get_winnr())
end

function M.setup(opts)
Expand Down