Skip to content

Commit

Permalink
fix(table): do not shrink table height
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbunni committed Sep 23, 2024
1 parent 8315f21 commit 83bc923
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ func (t *Table) String() string {
topHeight := lipgloss.Height(sb.String()) - 1
availableLines := t.height - (topHeight + lipgloss.Height(bottom))

// if the height is larger than the number of rows, use the number
// of rows.
if availableLines > t.data.Rows() {
availableLines = t.data.Rows()
}
sb.WriteString(t.constructRows(availableLines))

default:
Expand Down Expand Up @@ -492,13 +497,19 @@ func (t *Table) constructRows(availableLines int) string {
offsetRowCount := t.data.Rows() - t.offset

// The number of rows to render. We always render at least one row.
rowsToRender := min(availableLines, offsetRowCount)
rowsToRender := availableLines
rowsToRender = max(rowsToRender, 1)

// Check if we need to render an overflow row.
needsOverflow := rowsToRender < offsetRowCount

// only use the offset as the starting value if there is overflow.
rowIdx := t.offset
if !needsOverflow {
// if there is no overflow, just render to the height of the table
// check there's enough content to fill the table
rowIdx = t.data.Rows() - rowsToRender
}
for rowsToRender > 0 && rowIdx < t.data.Rows() {
// Whenever the height is too small to render all rows, the bottom row will be an overflow row (ellipsis).
isOverflow := needsOverflow && rowsToRender == 1
Expand Down

0 comments on commit 83bc923

Please sign in to comment.