diff options
author | Piero Lescano <pierolescano@protonmail.com> | 2024-07-25 09:02:56 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-25 10:02:56 -0400 |
commit | 8422c49018116886ae23356c2101c9f7076c865b (patch) | |
tree | 9b75015baeefb4b1be8c78a7bcf74032e7d9c345 | |
parent | b0f441318812e547194face9cd8804fb0030e052 (diff) |
feat(filter): Add cyclic navigation (#483)
-rw-r--r-- | filter/filter.go | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/filter/filter.go b/filter/filter.go index 1b827eb..92b5677 100644 --- a/filter/filter.go +++ b/filter/filter.go @@ -255,29 +255,41 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { func (m *model) CursorUp() { if m.reverse { - m.cursor = clamp(0, len(m.matches)-1, m.cursor+1) + m.cursor = (m.cursor + 1) % len(m.matches) if len(m.matches)-m.cursor <= m.viewport.YOffset { - m.viewport.SetYOffset(len(m.matches) - m.cursor - 1) + m.viewport.LineUp(1) + } + if len(m.matches)-m.cursor > m.viewport.Height+m.viewport.YOffset { + m.viewport.SetYOffset(len(m.matches) - m.viewport.Height) } } else { - m.cursor = clamp(0, len(m.matches)-1, m.cursor-1) + m.cursor = (m.cursor - 1 + len(m.matches)) % len(m.matches) if m.cursor < m.viewport.YOffset { - m.viewport.SetYOffset(m.cursor) + m.viewport.LineUp(1) + } + if m.cursor >= m.viewport.YOffset+m.viewport.Height { + m.viewport.SetYOffset(len(m.matches) - m.viewport.Height) } } } func (m *model) CursorDown() { if m.reverse { - m.cursor = clamp(0, len(m.matches)-1, m.cursor-1) + m.cursor = (m.cursor - 1 + len(m.matches)) % len(m.matches) if len(m.matches)-m.cursor > m.viewport.Height+m.viewport.YOffset { m.viewport.LineDown(1) } + if len(m.matches)-m.cursor <= m.viewport.YOffset { + m.viewport.GotoTop() + } } else { - m.cursor = clamp(0, len(m.matches)-1, m.cursor+1) + m.cursor = (m.cursor + 1) % len(m.matches) if m.cursor >= m.viewport.YOffset+m.viewport.Height { m.viewport.LineDown(1) } + if m.cursor < m.viewport.YOffset { + m.viewport.GotoTop() + } } } |