bubbles
bubbles copied to clipboard
bug: table offsets too early when number of rows is less than height*2
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:
https://user-images.githubusercontent.com/16991201/230526308-a4ca7c4b-f8e3-4855-b7eb-7078c1bca7c3.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:
https://user-images.githubusercontent.com/16991201/230526301-6dbb04f6-e856-474b-a394-614ad2a06f49.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!