Skip to content

Commit

Permalink
feat(filter): Add cyclic navigation (#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
piero-vic authored Jul 25, 2024
1 parent b0f4413 commit 8422c49
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}

Expand Down

0 comments on commit 8422c49

Please sign in to comment.