Skip to content

Commit

Permalink
fix: truncate table when overflow (#685)
Browse files Browse the repository at this point in the history
This prevents a panic when rendering an empty right aligned and rightmost table cell
  • Loading branch information
YeungKC committed Dec 12, 2023
1 parent d19b266 commit aaeba27
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/widgets/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,12 @@ fn render_cell(buf: &mut Buffer, cell: &Cell, area: Rect) {
_ => 0,
};

buf.set_line(area.x + x_offset, area.y + i as u16, line, area.width);
let x = area.x + x_offset;
if x >= area.right() {
continue;
}

buf.set_line(x, area.y + i as u16, line, area.width);
}
}

Expand Down Expand Up @@ -1035,6 +1040,15 @@ mod tests {
assert_eq!(buf, expected);
}

#[test]
fn test_render_table_when_overflow() {
let mut buf = Buffer::empty(Rect::new(0, 0, 20, 3));
let table = Table::new(vec![], [Constraint::Min(20); 1])
.header(Row::new([Line::from("").alignment(Alignment::Right)]));

Widget::render(table, Rect::new(0, 0, 20, 3), &mut buf);
}

#[test]
fn cell_can_be_stylized() {
assert_eq!(
Expand Down

0 comments on commit aaeba27

Please sign in to comment.