From 8a64c33ce58a78a10f5f63c2960b0830c7aeea9b Mon Sep 17 00:00:00 2001 From: ayn2op Date: Fri, 7 Aug 2026 02:17:19 -0400 Subject: [PATCH] refactor(chat): adapt to tree view changes --- go.mod | 2 +- go.sum | 4 ++-- internal/ui/chat/guilds_tree.go | 29 ++++++++--------------------- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index 4d08100..cf5232b 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/andybalholm/brotli v1.2.2 github.com/ayn2op/arikawa/v3 v3.0.0-20260708075022-9cc760fe507e github.com/ayn2op/ningen/v3 v3.0.1-0.20260708075321-0ba1ffc70bd6 - github.com/ayn2op/tview v0.0.0-20260806205637-7fdbc79aff89 + github.com/ayn2op/tview v0.0.0-20260807061323-573f4b04d4a8 github.com/bogdanfinn/fhttp v0.6.8 github.com/bogdanfinn/tls-client v1.15.1 github.com/gdamore/tcell/v3 v3.4.1 diff --git a/go.sum b/go.sum index 530c23f..9835fbc 100644 --- a/go.sum +++ b/go.sum @@ -14,8 +14,8 @@ github.com/ayn2op/arikawa/v3 v3.0.0-20260708075022-9cc760fe507e h1:rsMifRXwxkbha github.com/ayn2op/arikawa/v3 v3.0.0-20260708075022-9cc760fe507e/go.mod h1:gqklpHK7WHYTzpd1ZY6Ho/p9GURBghzBCzRiBYpaUP8= github.com/ayn2op/ningen/v3 v3.0.1-0.20260708075321-0ba1ffc70bd6 h1:/khHm6G+GWwXpmwA8bJoaXoUhubqMEUG6spjZsnklIw= github.com/ayn2op/ningen/v3 v3.0.1-0.20260708075321-0ba1ffc70bd6/go.mod h1:vqLIvETLkjc2vIgQzVEBqpGNCrgNe7YJqS9TUAJsXRI= -github.com/ayn2op/tview v0.0.0-20260806205637-7fdbc79aff89 h1:/cvaZ7JUGRuclbqkWsH435iuW5DmiGOr/hV8sJ8SSHI= -github.com/ayn2op/tview v0.0.0-20260806205637-7fdbc79aff89/go.mod h1:bJZdl/FfspPLEW3nuX6ubt7YbmDoSj7f2IoWH37w1NE= +github.com/ayn2op/tview v0.0.0-20260807061323-573f4b04d4a8 h1:IZVthAp7XM3Z3EZX6mjtgbJUMVzJiYpJcU+5PN9k1J4= +github.com/ayn2op/tview v0.0.0-20260807061323-573f4b04d4a8/go.mod h1:bJZdl/FfspPLEW3nuX6ubt7YbmDoSj7f2IoWH37w1NE= github.com/bdandy/go-errors v1.2.2 h1:WdFv/oukjTJCLa79UfkGmwX7ZxONAihKu4V0mLIs11Q= github.com/bdandy/go-errors v1.2.2/go.mod h1:NkYHl4Fey9oRRdbB1CoC6e84tuqQHiqrOcZpqFEkBxM= github.com/bdandy/go-socks4 v1.2.3 h1:Q6Y2heY1GRjCtHbmlKfnwrKVU/k81LS8mRGLRlmDlic= diff --git a/internal/ui/chat/guilds_tree.go b/internal/ui/chat/guilds_tree.go index 7376a4a..8997390 100644 --- a/internal/ui/chat/guilds_tree.go +++ b/internal/ui/chat/guilds_tree.go @@ -326,17 +326,13 @@ func (gt *guildsTree) loadChannel(channel discord.Channel) tview.Cmd { } func (gt *guildsTree) collapseParentNode(node *tree.Node) { - gt. - Root(). - Walk(func(n, parent *tree.Node) bool { - if n == node && parent.GetLevel() != 0 { - parent.Collapse() - gt.SetCurrentNode(parent) - return false - } - - return true - }) + path := gt.GetPath(node) + if len(path) < 3 { + return + } + parent := path[len(path)-2] + parent.Collapse() + gt.SetCurrentNode(parent) } func (gt *guildsTree) Update(msg tview.Msg) tview.Cmd { @@ -490,16 +486,7 @@ func (gt *guildsTree) collapseKeybinds() []keybind.Keybind { } func (gt *guildsTree) canCollapseParent(node *tree.Node) bool { - if node == nil { - return false - } - path := gt.GetPath(node) - // Path layout is [root, ..., node]. A non-root parent means at least 3 nodes. - if len(path) < 3 { - return false - } - parent := path[len(path)-2] - return parent != nil && parent.GetLevel() != 0 + return node != nil && len(gt.GetPath(node)) >= 3 } func (gt *guildsTree) canCollapseAll() bool {