Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions table/row.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ func (m Model) renderRowColumnData(row Row, column Column, rowStyle lipgloss.Sty

if m.multiline {
str = ansi.Wordwrap(str, contentWidth, "")
// a bug in Wordwrap means when hyphens are used as a breakpoint, the wrap is done AFTER the hyphen
// resulting in a line that exceeds the column width
// Hardwrap as a seconds step avoids this
str = ansi.Hardwrap(str, contentWidth, false)
cellStyle = cellStyle.Align(lipgloss.Top)
} else {
str = limitStr(str, contentWidth)
Expand Down
24 changes: 24 additions & 0 deletions table/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1779,6 +1779,30 @@ func TestMultilineDisabledExplicite(t *testing.T) {
assert.Equal(t, expectedTable, rendered)
}

func TestMultilineHyphenDoesNotOverflowColumnWidth(t *testing.T) {
// Wordwrap treats hyphens as break points and places the hyphen at the END
// of the wrapped line (e.g. "abcdefgh-" = 9 chars for a width-8 column).
// The Hardwrap pass that follows must clip that back to the column width so
// the cell never overflows.
model := New([]Column{
NewColumn("content", "Content", 8),
}).
WithRows([]Row{
NewRow(RowData{"content": "abcdefgh-tail"}),
}).
WithMultiline(true)

const expected = `┏━━━━━━━━┓
┃ Content┃
┣━━━━━━━━┫
┃abcdefgh┃
┃- ┃
┃tail ┃
┗━━━━━━━━┛`

assert.Equal(t, expected, model.View())
}

func TestRowBorder3x3(t *testing.T) {
model := New([]Column{
NewColumn("1", "1", 4),
Expand Down
Loading