Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#109): add PageUp/PageDown scrolling to fuzzy find view #111

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
}
}
Loading