Skip to content

Commit

Permalink
fix(cellbuf): ignore space cells when rendering a line
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Oct 17, 2024
1 parent c1ddd1f commit f2394f7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cellbuf/grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func RenderLine(g Grid, n int) (w int, line string) {
var pen Style
var link Link
var buf bytes.Buffer
var pendingLine string
var pendingWidth int // this ignores space cells until we hit a non-space cell
for x := 0; x < g.Width(); x++ {
if cell, err := g.At(x, n); err == nil && cell.Width > 0 {
if cell.Style.Empty() && !pen.Empty() {
Expand All @@ -86,8 +88,17 @@ func RenderLine(g Grid, n int) (w int, line string) {
link = cell.Link
}

w += cell.Width
buf.WriteString(cell.Content)
// We only write the cell content if it's not empty. If it is, we
// append it to the pending line and width to be evaluated later.
if len(strings.TrimSpace(cell.Content)) == 0 {
pendingLine += cell.Content
pendingWidth += cell.Width
} else {
buf.WriteString(pendingLine + cell.Content)
w += pendingWidth + cell.Width
pendingWidth = 0
pendingLine = ""
}
}
}
if link.URL != "" {
Expand Down

0 comments on commit f2394f7

Please sign in to comment.