From e7748f085640b94ce6dcdc7ed599ca8169cddf45 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Fri, 30 May 2025 16:55:34 -0300 Subject: [PATCH] fix(table): add fixes to `pageup`/`pagedown` --- table/table.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/table/table.go b/table/table.go index 0f1cee5..75ed35b 100644 --- a/table/table.go +++ b/table/table.go @@ -408,9 +408,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { if !m.focus { return m, nil } - table := m.table.String() - // XXX: make this not hard coded? - height := lipgloss.Height(table) - 6 + height := m.table.VisibleRows() - 1 switch msg := msg.(type) { case tea.KeyPressMsg: @@ -420,9 +418,17 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { case key.Matches(msg, m.KeyMap.LineDown): m.MoveDown(1) case key.Matches(msg, m.KeyMap.PageUp): - m.MoveUp(height) + if m.cursor > m.table.FirstVisibleRowIndex() { + m.SetCursor(m.table.FirstVisibleRowIndex()) + } else { + m.MoveUp(height) + } case key.Matches(msg, m.KeyMap.PageDown): - m.MoveDown(height) + if m.cursor < m.table.LastVisibleRowIndex() { + m.SetCursor(m.table.LastVisibleRowIndex()) + } else { + m.MoveDown(height) + } case key.Matches(msg, m.KeyMap.HalfPageUp): m.MoveUp(height / 2) //nolint:mnd case key.Matches(msg, m.KeyMap.HalfPageDown):