diff options
Diffstat (limited to 'filter/filter.go')
-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() + } } } |