summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Muehlhaeuser <muesli@gmail.com>2022-10-10 00:54:59 +0200
committerChristian Muehlhaeuser <muesli@gmail.com>2022-10-10 00:54:59 +0200
commit62cd81daaffaf3274e9275191934717d4fc53936 (patch)
treea6377af69eb45919dfcf61f410f60a8dd9c268f4
parent1426c2fed979bcad0d3e97cdf2da49ee877af9f4 (diff)
feat: support page up/down in filter modelpage-updown
-rw-r--r--filter/filter.go36
1 files changed, 24 insertions, 12 deletions
diff --git a/filter/filter.go b/filter/filter.go
index 41c14e7..4f9986f 100644
--- a/filter/filter.go
+++ b/filter/filter.go
@@ -146,22 +146,26 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "enter":
m.quitting = true
return m, tea.Quit
+ case "pgdown":
+ m.CursorPageDown()
+ case "pgup":
+ m.CursorPageUp()
case "ctrl+n", "ctrl+j", "down":
- m.CursorDown()
+ m.CursorDown(1)
case "ctrl+p", "ctrl+k", "up":
- m.CursorUp()
+ m.CursorUp(1)
case "tab":
if m.limit == 1 {
break // no op
}
m.ToggleSelection()
- m.CursorDown()
+ m.CursorDown(1)
case "shift+tab":
if m.limit == 1 {
break // no op
}
m.ToggleSelection()
- m.CursorUp()
+ m.CursorUp(1)
default:
m.textinput, cmd = m.textinput.Update(msg)
@@ -201,34 +205,42 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, cmd
}
-func (m *model) CursorUp() {
+func (m *model) CursorUp(n int) {
if m.reverse {
- m.cursor = clamp(0, len(m.matches)-1, m.cursor+1)
+ m.cursor = clamp(0, len(m.matches)-1, m.cursor+n)
if len(m.matches)-m.cursor <= m.viewport.YOffset {
m.viewport.SetYOffset(len(m.matches) - m.cursor - 1)
}
} else {
- m.cursor = clamp(0, len(m.matches)-1, m.cursor-1)
+ m.cursor = clamp(0, len(m.matches)-1, m.cursor-n)
if m.cursor < m.viewport.YOffset {
m.viewport.SetYOffset(m.cursor)
}
}
}
-func (m *model) CursorDown() {
+func (m *model) CursorDown(n int) {
if m.reverse {
- m.cursor = clamp(0, len(m.matches)-1, m.cursor-1)
+ m.cursor = clamp(0, len(m.matches)-1, m.cursor-n)
if len(m.matches)-m.cursor > m.viewport.Height+m.viewport.YOffset {
- m.viewport.LineDown(1)
+ m.viewport.LineDown(n)
}
} else {
- m.cursor = clamp(0, len(m.matches)-1, m.cursor+1)
+ m.cursor = clamp(0, len(m.matches)-1, m.cursor+n)
if m.cursor >= m.viewport.YOffset+m.viewport.Height {
- m.viewport.LineDown(1)
+ m.viewport.LineDown(n)
}
}
}
+func (m *model) CursorPageUp() {
+ m.CursorUp(m.viewport.Height)
+}
+
+func (m *model) CursorPageDown() {
+ m.CursorDown(m.viewport.Height)
+}
+
func (m *model) ToggleSelection() {
if _, ok := m.selected[m.matches[m.cursor].Str]; ok {
delete(m.selected, m.matches[m.cursor].Str)