@@ -25,7 +25,7 @@ func newRenderer() *renderer {
2525 return lipgloss .NewStyle ().PaddingRight (1 )
2626 },
2727 indenterFunc : func (Children , int ) lipgloss.Style {
28- return lipgloss .NewStyle ()
28+ return lipgloss .NewStyle (). PaddingRight ( 1 )
2929 },
3030 itemFunc : func (Children , int ) lipgloss.Style {
3131 return lipgloss .NewStyle ()
@@ -81,20 +81,22 @@ func (r *renderer) render(node Node, root bool, prefix string) string {
8181 }
8282 indentStyle := r .style .indenterFunc (children , i )
8383 enumStyle := r .style .enumeratorFunc (children , i )
84+
8485 itemStyle := r .style .itemFunc (children , i )
8586
86- indent := indenter (children , i )
87- nodeIndent := indentStyle .Render (indent )
87+ indent := indentStyle .Render (indenter (children , i ))
8888 nodePrefix := enumStyle .Render (enumerator (children , i ))
89+
90+ // Preserve the background color of the enumerator when adding the padding
91+ enumBgStyle := lipgloss .NewStyle ().Background (enumStyle .GetBackground ())
92+
93+ // Add padding to the left of the node to align it with the longest prefix of its siblings
8994 if l := maxLen - lipgloss .Width (nodePrefix ); l > 0 {
90- nodePrefix = enumStyle .Render (strings .Repeat (" " , l )) + nodePrefix
95+ nodePrefix = enumBgStyle .Render (strings .Repeat (" " , l )) + nodePrefix
9196 }
9297
9398 item := itemStyle .Render (child .Value ())
94- multineLinePrefix := prefix
95- if multineLinePrefix != "" {
96- multineLinePrefix = indentStyle .Render (multineLinePrefix )
97- }
99+ multineLinePrefix := enumBgStyle .Render (prefix )
98100
99101 // This dance below is to account for multiline prefixes, e.g. "|\n|".
100102 // In that case, we need to make sure that both the parent prefix and
@@ -103,14 +105,14 @@ func (r *renderer) render(node Node, root bool, prefix string) string {
103105 nodePrefix = lipgloss .JoinVertical (
104106 lipgloss .Left ,
105107 nodePrefix ,
106- nodeIndent ,
108+ indent ,
107109 )
108110 }
109111 for lipgloss .Height (nodePrefix ) > lipgloss .Height (multineLinePrefix ) {
110112 multineLinePrefix = lipgloss .JoinVertical (
111113 lipgloss .Left ,
112114 multineLinePrefix ,
113- indentStyle . Render ( prefix ) ,
115+ prefix ,
114116 )
115117 }
116118
0 commit comments