Closed dzeleniak closed 7 months ago
I have done a little digging on this issue.
It looks like the problem is in the bubbles package on the move-up command. Upon investigation it looks like the error is in the MoveUp function.
The following code fixes the issue.
// MoveUp moves the selection up by any number of rows.
// It can not go above the first row.
func (m *Model) MoveUp(n int) {
m.cursor = clamp(m.cursor-n, 0, len(m.rows)-1)
switch {
case m.start == 0:
m.viewport.SetYOffset(clamp(m.viewport.YOffset, 0, m.cursor))
case m.start < m.viewport.Height:
m.viewport.YOffset = clamp(clamp(m.viewport.YOffset+n, 0, m.cursor), 0, m.viewport.Height)
case m.viewport.YOffset >= 1:
m.viewport.YOffset = clamp(m.viewport.YOffset+n, 1, m.viewport.Height)
}
m.UpdateViewport()
}
Just as a note, #363 reports a similar problem but when scrolling down. I don't know if it is the same bug behind the scene, so just in case...
Thanks for the heads up! I'll take a look at this tomorrow.
This is a copy of an issue created on bubbletea.
"Here is a code sample that uses the table component. Something I noticed is that when I press the down arrow key, going from the first item to the last, everything works as expected. Going in the reverse direction, that is, going from the last item to the first one (via up arrow) the viewport is scrolled down before the selected line matches the top of the viewport. Check the animated gif on the entry labeled as Poland. What can be done so that going from the first item to last item and the opposite way (last to first) behaves exactly the same way?"