[GH-ISSUE #823] TreeView SetCurrentNode is not triggering changed callback #599

Closed
opened 2026-03-04 01:06:21 +03:00 by kerem · 3 comments
Owner

Originally created by @jdfa on GitHub (Mar 10, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/823

While it is really good that current behavior is documented in comment, I would like to have get different thing.

I am using TreeView and reimplemented navigation for few keys. It is nothing extraordinary: LeftArrow will switch to parent node, RightArrow - to first child with some extra conditions.
For that, In inputCapture I am calling SetCurrentNode which doesn't trigger changed callback. I would do that manually, but there is no method to access that callback.

Originally created by @jdfa on GitHub (Mar 10, 2023). Original GitHub issue: https://github.com/rivo/tview/issues/823 While it is really good that current behavior is documented in comment, I would like to have get different thing. I am using `TreeView` and reimplemented navigation for few keys. It is nothing extraordinary: LeftArrow will switch to parent node, RightArrow - to first child with some extra conditions. For that, In `inputCapture` I am calling `SetCurrentNode` which doesn't trigger `changed` callback. I would do that manually, but there is no method to access that callback.
kerem closed this issue 2026-03-04 01:06:21 +03:00
Author
Owner

@jdfa commented on GitHub (Mar 12, 2023):

@digitallyserviced Thanks, that helped me to find workaround. In my case I just moved my "OnChanged" logic from TreeView::SetChangedFunc to Application::SetBeforeDrawFunc.
But I am sure that this is not clean solution, TreeView api should handle such scenario.

<!-- gh-comment-id:1465221901 --> @jdfa commented on GitHub (Mar 12, 2023): @digitallyserviced Thanks, that helped me to find workaround. In my case I just moved my "OnChanged" logic from `TreeView::SetChangedFunc` to `Application::SetBeforeDrawFunc`. But I am sure that this is not clean solution, `TreeView` api should handle such scenario.
Author
Owner

@rivo commented on GitHub (Mar 25, 2023):

@digitallyserviced is right in that the call to the "changed" function is delayed until Draw is called next time. I would think, though, that if you rebind keys using SetInputCapture(), this would lead to a call to Draw immediately afterwards, thus triggering the "changed" callback. Without any more details, though, I can't tell why this isn't happening.

<!-- gh-comment-id:1483918122 --> @rivo commented on GitHub (Mar 25, 2023): @digitallyserviced is right in that the call to the "changed" function is delayed until `Draw` is called next time. I would think, though, that if you rebind keys using `SetInputCapture()`, this would lead to a call to `Draw` immediately afterwards, thus triggering the "changed" callback. Without any more details, though, I can't tell why this isn't happening.
Author
Owner

@rivo commented on GitHub (Mar 25, 2023):

Actually, looking at this again in some more detail, the way it was implemented, there was indeed no good way to trigger the "changed" callback when calling SetCurrentNode(). This should be fixed with the latest commit. It will still only be triggered during drawing, but it will be triggered in any case.

<!-- gh-comment-id:1483922536 --> @rivo commented on GitHub (Mar 25, 2023): Actually, looking at this again in some more detail, the way it was implemented, there was indeed no good way to trigger the "changed" callback when calling `SetCurrentNode()`. This should be fixed with the latest commit. It will still only be triggered during drawing, but it will be triggered in any case.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#599
No description provided.