charmbracelet / bubbles

TUI components for Bubble Tea 🫧

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bug: table offsets too early when number of rows is less than height*2

robherley opened this issue · comments

Using the example from the bubbletea repo where the table height is 10.

When the table is rendered with 100 rows, moving down scrolls normally and only offsetting at the last rendered row:

100rows.mov

However, if we render with 15 rows (just remove the other 85 in the example), the table offsets too early on the 5th element:

15rows.mov

For a table height of h, and a row length of n, this behavior is seen when h < n < 2h and will offset early on the n - h element

e.g. for a table height of 10 and len(rows) == 13, it offsets on the 3rd element

I was working on a table implemention with multi-select and I encountered the same problem after already implementing multi-select. My version fixes two scroll issues: the one mentioned here, and one in which a cursor move up from the last row causes an unneeded scroll up, which moves the last row out of view even when the height allows multiple rows to be shown.

I could do a PR if it is wanted, but my current implementation has multi-select. I only noticed the scrolling issue after adding multi-select. Let me know and I can separate the multi-select and scroll fixes.

https://github.com/Philistino/bubbles/blob/master/table/table.go

Fixed by #428. Thank you for the well-written / documented issue!