-
-
Notifications
You must be signed in to change notification settings - Fork 616
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
feat(event): add TreeRendered #2324
Conversation
Events were fired as expected in the correct order when exercising a variety of functionality. local Event = api.events.Event
api.events.subscribe(Event.TreeRendered, function()
log.line("dev", "TreeRendered")
end)
api.events.subscribe(Event.TreeAttachedPost, function()
log.line("dev", "TreeAttachedPost")
end)
api.events.subscribe(Event.TreeOpen, function()
log.line("dev", "TreeOpen")
end)
api.events.subscribe(Event.TreeClose, function()
log.line("dev", "TreeClose")
end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fantastic, thank you for the detailed analysis. This is the best solution.
Please:
- pass bufnr to the event as per
TreeAttachedPost
- (bonus) pass winid
We could pass bufnr/winid to TreeOpen
but that might be a little difficult.
If I understand well passing the buffer and the window is just a matter of calling the respective utility functions from Anyway I pushed the changes to add |
Yes. There is a lot of work to be done there: #2255 This event's buf/win will definitely be correct, and it saves the user from the extra api calls.
No need, we merge squash. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks for your contribution!
Hello
I stumbled upon a problem while trying to build myself some script saving/restoring some tree state upon editor start, specifically the cursor position and the folder expanded status.
While the folder expansion seems to work fine, I struggled with resetting the cursor position. The problem was that I was subscribing to the
TreeOpen
event, but that event only gives access to the empty tree window; the actual content is updated by the renderer. So when trying to set the cursor position from theTreeOpen
handler it did nothing because at that point the buffer only has 1 (empty) line.The way I see it there could be 2 possible solutions to this:
events._dispatch_on_tree_open()
should be called every time the tree window is opened after any subsequent call torenderer.draw()
TreeOpen
to perform operations on the rendered bufferBoth have pros and cons. In this PR I'm going for the second one, hopefully the summary below will explain why.
Of course if I missed something stupid feel free to point it out and close this PR 😁 I was a bit unsure if I needed to open an issue first, but once I tried to fix the thing I saw that was simple enough so I just pushed the code changes.
Dispatch
TreeOpen
on any open + redrawPros:
Cons:
open
function is called in many places)Introduce the new
TreeRendered
eventPros:
Cons: