From 3cec9b7b9a5395b6d41620789b2197cb76330062 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Mon, 18 Nov 2024 10:00:10 -0300 Subject: [PATCH] fix(filter): panic if no matches closes #715 Signed-off-by: Carlos Alexandro Becker --- filter/filter.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/filter/filter.go b/filter/filter.go index 3ed1e78d9..6b51e7c46 100644 --- a/filter/filter.go +++ b/filter/filter.go @@ -255,6 +255,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } func (m *model) CursorUp() { + if len(m.matches) == 0 { + return + } if m.reverse { //nolint:nestif m.cursor = (m.cursor + 1) % len(m.matches) if len(m.matches)-m.cursor <= m.viewport.YOffset { @@ -275,6 +278,9 @@ func (m *model) CursorUp() { } func (m *model) CursorDown() { + if len(m.matches) == 0 { + return + } if m.reverse { //nolint:nestif m.cursor = (m.cursor - 1 + len(m.matches)) % len(m.matches) if len(m.matches)-m.cursor > m.viewport.Height+m.viewport.YOffset {