Skip to content

Commit 6e95d19

Browse files
committed
feat: handle pgup and pgdown in revisions view
fixes #347
1 parent 93c1757 commit 6e95d19

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

internal/ui/revisions/revisions.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ var _ list.IListCursor = (*Model)(nil)
4141
var _ common.Focusable = (*Model)(nil)
4242
var _ common.Editable = (*Model)(nil)
4343

44+
var pageDownKey = key.NewBinding(key.WithKeys("pgdown"))
45+
var pageUpKey = key.NewBinding(key.WithKeys("pgup"))
46+
4447
type Model struct {
4548
*common.Sizeable
4649
rows []parser.Row
@@ -351,14 +354,22 @@ func (m *Model) internalUpdate(msg tea.Msg) (*Model, tea.Cmd) {
351354
switch msg := msg.(type) {
352355
case tea.KeyMsg:
353356
switch {
354-
case key.Matches(msg, m.keymap.Up):
355-
if m.cursor > 0 {
356-
m.cursor--
357+
case key.Matches(msg, m.keymap.Up, pageUpKey):
358+
amount := 1
359+
if key.Matches(msg, pageUpKey) && m.renderer.LastRowIndex > m.renderer.FirstRowIndex {
360+
amount = m.renderer.LastRowIndex - m.renderer.FirstRowIndex - 1
361+
}
362+
if m.cursor-amount >= 0 {
363+
m.cursor = m.cursor - amount
357364
}
358365
return m, m.updateSelection()
359-
case key.Matches(msg, m.keymap.Down):
360-
if m.cursor < len(m.rows)-1 {
361-
m.cursor++
366+
case key.Matches(msg, m.keymap.Down, pageDownKey):
367+
amount := 1
368+
if key.Matches(msg, pageDownKey) && m.renderer.LastRowIndex > m.renderer.FirstRowIndex {
369+
amount = m.renderer.LastRowIndex - m.renderer.FirstRowIndex - 1
370+
}
371+
if m.cursor < len(m.rows)-amount {
372+
m.cursor = m.cursor + amount
362373
} else if m.hasMore {
363374
return m, m.requestMoreRows(m.tag.Load())
364375
}

0 commit comments

Comments
 (0)