diff options
author | Maas Lalani <maas@lalani.dev> | 2022-08-18 17:12:00 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-18 17:12:00 -0400 |
commit | 08346909a9f79df441cfe65d1141d9f0ded76c40 (patch) | |
tree | 6367f875143a6b3bd250dba6a4e82f2886fbe488 | |
parent | 5f4cc48069905c9842416882ba8b4fbb044c2b7d (diff) |
feat(choose): Wrap around choose list and `g`/`G` keybindings (#122)v0.5.0
* `G` goes to last element / `g` goes to first element
* Wrap around on first and last elements
-rw-r--r-- | choose/choose.go | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/choose/choose.go b/choose/choose.go index 30ed74b..7d0ddbd 100644 --- a/choose/choose.go +++ b/choose/choose.go @@ -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 |