Skip to content

Commit

Permalink
feat(choose): Wrap around choose list and g/G keybindings (#122)
Browse files Browse the repository at this point in the history
* `G` goes to last element / `g` goes to first element
* Wrap around on first and last elements
  • Loading branch information
maaslalani authored Aug 18, 2022
1 parent 5f4cc48 commit 0834690
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions choose/choose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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
Expand Down

0 comments on commit 0834690

Please sign in to comment.