Skip to content

Commit

Permalink
feat: improves selected node color calculation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgerojas26 committed Sep 4, 2024
1 parent 74bec9c commit 7d23ae6
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions components/Tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,21 @@ func NewTree(dbName string, dbdriver drivers.Driver) *Tree {
tree.SetFocusFunc(nil)
})

tree.SetChangedFunc(func(node *tview.TreeNode) {
rootNode.Walk(func(n, _ *tview.TreeNode) bool {
nodeText := n.GetText()

splittedNodeText := strings.Split(nodeText, "]")

if len(splittedNodeText) > 1 {
n.SetText(splittedNodeText[1])
}

return true
})
previouslyFocusedNode := tree.GetCurrentNode()
previouslyFocusedNode.SetText(fmt.Sprintf("[black:%s]%s", tview.Styles.SecondaryTextColor.Name(), previouslyFocusedNode.GetText()))

tree.SetChangedFunc(func(node *tview.TreeNode) {
// Set colors on focused node
nodeText := node.GetText()
node.SetText(fmt.Sprintf("[%s:dark]%s", tview.Styles.SecondaryTextColor.Name(), nodeText))
node.SetText(fmt.Sprintf("[black:%s]%s", tview.Styles.SecondaryTextColor.Name(), nodeText))

// Remove colors on previously focused node
previousNodeText := previouslyFocusedNode.GetText()
splittedNodeText := strings.Split(previousNodeText, "]")
if len(splittedNodeText) > 1 {
previouslyFocusedNode.SetText(splittedNodeText[1])
}
previouslyFocusedNode = node
})

tree.SetSelectedFunc(func(node *tview.TreeNode) {
Expand Down

0 comments on commit 7d23ae6

Please sign in to comment.