From 5c7d71700b8c7cba35fa925f7f4dcba289bb990d Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Thu, 13 Feb 2020 10:00:20 -0800 Subject: [PATCH] Fix scrolling table with PageDown and PageUp Resolves #402. --- table.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/table.go b/table.go index 9d0db29..9f6226c 100644 --- a/table.go +++ b/table.go @@ -1101,27 +1101,37 @@ func (t *Table) InputHandler() func(event *tcell.EventKey, setFocus func(p Primi } pageDown = func() { + offsetAmount := t.visibleRows - t.fixedRows + if offsetAmount < 0 { + offsetAmount = 0 + } + if t.rowsSelectable { - t.selectedRow += t.visibleRows + t.selectedRow += offsetAmount if t.selectedRow >= len(t.cells) { t.selectedRow = len(t.cells) - 1 } next() } else { - t.rowOffset += t.visibleRows + t.rowOffset += offsetAmount } } pageUp = func() { + offsetAmount := t.visibleRows - t.fixedRows + if offsetAmount < 0 { + offsetAmount = 0 + } + if t.rowsSelectable { - t.selectedRow -= t.visibleRows + t.selectedRow -= offsetAmount if t.selectedRow < 0 { t.selectedRow = 0 } previous() } else { t.trackEnd = false - t.rowOffset -= t.visibleRows + t.rowOffset -= offsetAmount } } )