ui.go 513 B

1234567891011121314151617
  1. package util
  2. import "github.com/rivo/tview"
  3. // GetTreeNodeByReference walks the root `*TreeNode` of the given `*TreeView` *treeView* and returns the TreeNode whose reference is equal to the given reference *r*. If the `*TreeNode` is not found, `nil` is returned instead.
  4. func GetTreeNodeByReference(treeView *tview.TreeView, r interface{}) (mn *tview.TreeNode) {
  5. treeView.GetRoot().Walk(func(n, _ *tview.TreeNode) bool {
  6. if n.GetReference() == r {
  7. mn = n
  8. return false
  9. }
  10. return true
  11. })
  12. return
  13. }