@@ -152,11 +152,10 @@ impl FuzzySelect<'_> {
152
152
// Fuzzy matcher
153
153
let matcher = fuzzy_matcher:: skim:: SkimMatcherV2 :: default ( ) ;
154
154
155
- let term_size_rows = term. size ( ) . 0 as usize ;
156
155
// Subtract -2 because we need space to render the prompt.
157
- let visible_term_rows = term_size_rows
158
- . max ( 3 ) // Safeguard in case term_size_rows is 2 or less .
159
- - 2 ;
156
+ let visible_term_rows = ( term . size ( ) . 0 as usize ) . max ( 3 ) - 2 ;
157
+ // Variable used to determine if we need to scroll through the list .
158
+ let mut starting_row = 0 ;
160
159
161
160
term. hide_cursor ( ) ?;
162
161
@@ -170,13 +169,17 @@ impl FuzzySelect<'_> {
170
169
. iter ( )
171
170
. map ( |item| ( item, matcher. fuzzy_match ( item, & search_term) ) )
172
171
. filter_map ( |( item, score) | score. map ( |s| ( item, s) ) )
173
- . take ( visible_term_rows)
174
172
. collect :: < Vec < _ > > ( ) ;
175
173
176
174
// Renders all matching items, from best match to worst.
177
175
filtered_list. sort_unstable_by ( |( _, s1) , ( _, s2) | s2. cmp ( & s1) ) ;
178
176
179
- for ( idx, ( item, _) ) in filtered_list. iter ( ) . enumerate ( ) {
177
+ for ( idx, ( item, _) ) in filtered_list
178
+ . iter ( )
179
+ . enumerate ( )
180
+ . skip ( starting_row)
181
+ . take ( visible_term_rows)
182
+ {
180
183
render. select_prompt_item ( item, idx == sel) ?;
181
184
term. flush ( ) ?;
182
185
}
@@ -191,6 +194,12 @@ impl FuzzySelect<'_> {
191
194
return Ok ( None ) ;
192
195
}
193
196
Key :: ArrowUp | Key :: BackTab if filtered_list. len ( ) > 0 => {
197
+ if sel == 0 {
198
+ starting_row =
199
+ filtered_list. len ( ) . max ( visible_term_rows) - visible_term_rows;
200
+ } else if sel == starting_row {
201
+ starting_row -= 1 ;
202
+ }
194
203
if sel == !0 {
195
204
sel = filtered_list. len ( ) - 1 ;
196
205
} else {
@@ -205,6 +214,11 @@ impl FuzzySelect<'_> {
205
214
} else {
206
215
sel = ( sel as u64 + 1 ) . rem ( filtered_list. len ( ) as u64 ) as usize ;
207
216
}
217
+ if sel == visible_term_rows + starting_row {
218
+ starting_row += 1 ;
219
+ } else if sel == 0 {
220
+ starting_row = 0 ;
221
+ }
208
222
term. flush ( ) ?;
209
223
}
210
224
Key :: ArrowLeft if position > 0 => {
@@ -242,6 +256,7 @@ impl FuzzySelect<'_> {
242
256
position += 1 ;
243
257
term. flush ( ) ?;
244
258
sel = 0 ;
259
+ starting_row = 0 ;
245
260
}
246
261
247
262
_ => { }
0 commit comments