Skip to content

Commit

Permalink
Fix wrong rendering with two empty annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
meyermarcel committed Jun 5, 2024
1 parent 23b047a commit 042b314
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions annot.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,12 @@ func Write(w io.Writer, annots ...*Annot) error {
for _, a := range annots {
if len(a.Lines) == 0 {
a.lines = append(a.lines, &line{})
break
continue
}
a.lines = make([]*line, len(a.Lines))
for i := range a.Lines {
a.lines[i] = &line{
// 3 for "└─ " or " " (indentation)
length: 3 + utf8.RuneCountInString(a.Lines[i]),
length: utf8.RuneCountInString(a.Lines[i]),
leadingSpaces: a.Col,
}
}
Expand Down Expand Up @@ -153,7 +152,8 @@ func checkLineAndSetSpace(row, aLineIdx int, a *Annot, rightAnnots []*Annot) boo
return true
}

lineLength := a.lines[aLineIdx].length
// 3 for "└─ " or " " (indentation)
lineLength := 3 + a.lines[aLineIdx].length

remainingSpaces := closestA.Col - a.Col - lineLength

Expand Down
14 changes: 14 additions & 0 deletions annot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ func TestWrite(t *testing.T) {
wantW: `
└─
`,
wantErr: false,
},
{
name: "two empty annotations",
annots: []*Annot{
{Col: 0},
{Col: 2},
},
wantW: `
↑ ↑
│ └─
└─
`,
wantErr: false,
},
Expand Down

0 comments on commit 042b314

Please sign in to comment.