diff --git a/internal/app/fuzzy_find.go b/internal/app/fuzzy_find.go index e894f50..92a6dbe 100644 --- a/internal/app/fuzzy_find.go +++ b/internal/app/fuzzy_find.go @@ -194,6 +194,14 @@ func (f *FuzzyFind) HandleKeyEvent(ev *tcell.EventKey) { f.selected = ClampInt(f.selected-1, 0, f.matches.Len()-1) return } + if ev.Key() == tcell.KeyPgUp { + f.selected = ClampInt(f.selected+10, 0, f.matches.Len()-1) + return + } + if ev.Key() == tcell.KeyPgDn { + f.selected = ClampInt(f.selected-10, 0, f.matches.Len()-1) + return + } if f.isEventWritable(ev) { f.buffer.WriteRune(ev.Rune()) f.markAsDirty() diff --git a/internal/app/fuzzy_find_test.go b/internal/app/fuzzy_find_test.go index 717b2d6..e22b5fd 100644 --- a/internal/app/fuzzy_find_test.go +++ b/internal/app/fuzzy_find_test.go @@ -55,8 +55,13 @@ func TestFuzzyFind_Draw(t *testing.T) { } func TestFuzzyFind_HandleKeyEvent(t *testing.T) { + screen := tcell.NewSimulationScreen("utf-8") + _ = screen.Init() //nolint:errcheck + CreateNewAppWithScreen(screen) + type args struct { - ev []*tcell.EventKey + ev []*tcell.EventKey + expectedSelection int } tests := []struct { name string @@ -67,13 +72,20 @@ func TestFuzzyFind_HandleKeyEvent(t *testing.T) { tcell.NewEventKey(tcell.KeyUp, 0, tcell.ModNone), tcell.NewEventKey(tcell.KeyUp, 0, tcell.ModNone), tcell.NewEventKey(tcell.KeyDown, 0, tcell.ModNone), - }}}, + }, expectedSelection: 2}}, {"should go up, and go down using tab/tab-shift", args{ev: []*tcell.EventKey{ tcell.NewEventKey(tcell.KeyTab, 0, tcell.ModNone), tcell.NewEventKey(tcell.KeyTab, 0, tcell.ModNone), tcell.NewEventKey(tcell.KeyTab, 0, tcell.ModNone), tcell.NewEventKey(tcell.KeyBacktab, 0, tcell.ModNone), - }}}, + }, expectedSelection: 2}}, + {"should go up with page up", args{ev: []*tcell.EventKey{ + tcell.NewEventKey(tcell.KeyPgUp, 0, tcell.ModNone), + }, expectedSelection: 3}}, + {"should go down with page down", args{ev: []*tcell.EventKey{ + tcell.NewEventKey(tcell.KeyPgUp, 0, tcell.ModNone), + tcell.NewEventKey(tcell.KeyPgDn, 0, tcell.ModNone), + }, expectedSelection: 0}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -88,7 +100,7 @@ func TestFuzzyFind_HandleKeyEvent(t *testing.T) { } // then - assert.Equal(t, 2, fuzzyFind.selected) + assert.Equal(t, tt.args.expectedSelection, fuzzyFind.selected) }) } }