Skip to content

Commit

Permalink
fix: toc width
Browse files Browse the repository at this point in the history
  • Loading branch information
dlvhdr committed Oct 19, 2024
1 parent 438e5f0 commit 5cc9580
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions examples/tree-toc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5cc9580

Please sign in to comment.