From 5cc95807e795a46e09c8bf6e6971adf6299ff75c Mon Sep 17 00:00:00 2001 From: Dolev Hadar Date: Sat, 19 Oct 2024 23:30:34 +0300 Subject: [PATCH] fix: toc width --- examples/tree-toc/main.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/examples/tree-toc/main.go b/examples/tree-toc/main.go index 8a3741f124..af0ec4a35b 100644 --- a/examples/tree-toc/main.go +++ b/examples/tree-toc/main.go @@ -35,15 +35,12 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } func (m *model) childWidth(child *tree.Node) int { - w := width - enumeratorWidth*child.Depth() + w := width - enumeratorWidth*child.Depth() + 1 if strings.HasPrefix(child.Value(), m.tree.OpenCharacter) { - w -= lipgloss.Width(m.tree.OpenCharacter) + w += lipgloss.Width(m.tree.OpenCharacter) } else if strings.HasPrefix(child.Value(), m.tree.ClosedCharacter) { - w -= lipgloss.Width(m.tree.ClosedCharacter) - } else { - w -= lipgloss.Width(" ") + w += lipgloss.Width(m.tree.ClosedCharacter) } - return w } @@ -140,8 +137,8 @@ func main() { width, height, ) - t.OpenCharacter = "📖" t.ClosedCharacter = "📘" + t.OpenCharacter = "📖" if _, err := tea.NewProgram(model{tree: t}).Run(); err != nil { fmt.Println("Oh no:", err)