Skip to content

Commit 3fb0df0

Browse files
committed
feat(#109): add PageUp/PageDown scrolling to fuzzy find view
1 parent 9d41140 commit 3fb0df0

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

internal/app/fuzzy_find.go

+8
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ func (f *FuzzyFind) HandleKeyEvent(ev *tcell.EventKey) {
194194
f.selected = ClampInt(f.selected-1, 0, f.matches.Len()-1)
195195
return
196196
}
197+
if ev.Key() == tcell.KeyPgUp {
198+
f.selected = ClampInt(f.selected+10, 0, f.matches.Len()-1)
199+
return
200+
}
201+
if ev.Key() == tcell.KeyPgDn {
202+
f.selected = ClampInt(f.selected-10, 0, f.matches.Len()-1)
203+
return
204+
}
197205
if f.isEventWritable(ev) {
198206
f.buffer.WriteRune(ev.Rune())
199207
f.markAsDirty()

internal/app/fuzzy_find_test.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@ func TestFuzzyFind_Draw(t *testing.T) {
5555
}
5656

5757
func TestFuzzyFind_HandleKeyEvent(t *testing.T) {
58+
screen := tcell.NewSimulationScreen("utf-8")
59+
_ = screen.Init() //nolint:errcheck
60+
CreateNewAppWithScreen(screen)
61+
5862
type args struct {
59-
ev []*tcell.EventKey
63+
ev []*tcell.EventKey
64+
expectedSelection int
6065
}
6166
tests := []struct {
6267
name string
@@ -67,13 +72,20 @@ func TestFuzzyFind_HandleKeyEvent(t *testing.T) {
6772
tcell.NewEventKey(tcell.KeyUp, 0, tcell.ModNone),
6873
tcell.NewEventKey(tcell.KeyUp, 0, tcell.ModNone),
6974
tcell.NewEventKey(tcell.KeyDown, 0, tcell.ModNone),
70-
}}},
75+
}, expectedSelection: 2}},
7176
{"should go up, and go down using tab/tab-shift", args{ev: []*tcell.EventKey{
7277
tcell.NewEventKey(tcell.KeyTab, 0, tcell.ModNone),
7378
tcell.NewEventKey(tcell.KeyTab, 0, tcell.ModNone),
7479
tcell.NewEventKey(tcell.KeyTab, 0, tcell.ModNone),
7580
tcell.NewEventKey(tcell.KeyBacktab, 0, tcell.ModNone),
76-
}}},
81+
}, expectedSelection: 2}},
82+
{"should go up with page up", args{ev: []*tcell.EventKey{
83+
tcell.NewEventKey(tcell.KeyPgUp, 0, tcell.ModNone),
84+
}, expectedSelection: 3}},
85+
{"should go down with page down", args{ev: []*tcell.EventKey{
86+
tcell.NewEventKey(tcell.KeyPgUp, 0, tcell.ModNone),
87+
tcell.NewEventKey(tcell.KeyPgDn, 0, tcell.ModNone),
88+
}, expectedSelection: 0}},
7789
}
7890
for _, tt := range tests {
7991
t.Run(tt.name, func(t *testing.T) {
@@ -88,7 +100,7 @@ func TestFuzzyFind_HandleKeyEvent(t *testing.T) {
88100
}
89101

90102
// then
91-
assert.Equal(t, 2, fuzzyFind.selected)
103+
assert.Equal(t, tt.args.expectedSelection, fuzzyFind.selected)
92104
})
93105
}
94106
}

0 commit comments

Comments
 (0)