From e521fea98ed2c48d949092314a2d42b10a45702b Mon Sep 17 00:00:00 2001 From: David Zeleniak <20673621+dzeleniak@users.noreply.github.com> Date: Wed, 13 Mar 2024 11:39:10 -0700 Subject: [PATCH] fix(table): table scrolls before selected reaches top/bottom (#429) * Fix bug in moving up in table * fix * Fix table viewport scroll down too early --- table/table.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/table/table.go b/table/table.go index f0064fc8..7bff0901 100644 --- a/table/table.go +++ b/table/table.go @@ -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) } @@ -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: