Skip to content

Commit

Permalink
feat(#109): add PageUp/PageDown scrolling to fuzzy find view
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-5 committed Feb 1, 2024
1 parent 9d41140 commit 3fb0df0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
8 changes: 8 additions & 0 deletions internal/app/fuzzy_find.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 16 additions & 4 deletions internal/app/fuzzy_find_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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)
})
}
}

0 comments on commit 3fb0df0

Please sign in to comment.