Skip to content

Commit

Permalink
fix(table): table scrolls before selected reaches top/bottom (charmbr…
Browse files Browse the repository at this point in the history
…acelet#429)

* Fix bug in moving up in table

* fix

* Fix table viewport scroll down too early
  • Loading branch information
dzeleniak authored Mar 13, 2024
1 parent fd858c9 commit e521fea
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (m *Model) MoveUp(n int) {
case m.start == 0:
m.viewport.SetYOffset(clamp(m.viewport.YOffset, 0, m.cursor))
case m.start < m.viewport.Height:
m.viewport.SetYOffset(clamp(m.viewport.YOffset+n, 0, m.cursor))
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)
}
Expand All @@ -361,9 +361,9 @@ func (m *Model) MoveDown(n int) {
m.UpdateViewport()

switch {
case m.end == len(m.rows):
case m.end == len(m.rows) && m.viewport.YOffset > 0:
m.viewport.SetYOffset(clamp(m.viewport.YOffset-n, 1, m.viewport.Height))
case m.cursor > (m.end-m.start)/2:
case m.cursor > (m.end-m.start)/2 && m.viewport.YOffset > 0:
m.viewport.SetYOffset(clamp(m.viewport.YOffset-n, 1, m.cursor))
case m.viewport.YOffset > 1:
case m.cursor > m.viewport.YOffset+m.viewport.Height-1:
Expand Down

0 comments on commit e521fea

Please sign in to comment.