feat(choose): Wrap around choose list and g/G keybindings (#122)

* `G` goes to last element / `g` goes to first element
* Wrap around on first and last elements
This commit is contained in:
Maas Lalani 2022-08-18 17:12:00 -04:00 committed by GitHub
parent 5f4cc48069
commit 08346909a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -55,12 +55,20 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
start, end := m.paginator.GetSliceBounds(len(m.items))
switch keypress := msg.String(); keypress {
case "down", "j", "ctrl+n":
m.index = clamp(m.index+1, 0, len(m.items)-1)
m.index++
if m.index >= len(m.items) {
m.index = 0
m.paginator.Page = 0
}
if m.index >= end {
m.paginator.NextPage()
}
case "up", "k", "ctrl+p":
m.index = clamp(m.index-1, 0, len(m.items)-1)
m.index--
if m.index < 0 {
m.index = len(m.items) - 1
m.paginator.Page = m.paginator.TotalPages - 1
}
if m.index < start {
m.paginator.PrevPage()
}
@ -70,6 +78,12 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "left", "h", "ctrl+b":
m.index = clamp(m.index-m.height, 0, len(m.items)-1)
m.paginator.PrevPage()
case "G":
m.index = len(m.items) - 1
m.paginator.Page = m.paginator.TotalPages - 1
case "g":
m.index = 0
m.paginator.Page = 0
case "a":
if m.limit <= 1 {
break