@@ -209,6 +209,8 @@ impl FuzzySelect<'_> {
209
209
210
210
term. hide_cursor ( ) ?;
211
211
212
+ let mut vim_mode = false ;
213
+
212
214
loop {
213
215
render. clear ( ) ?;
214
216
render. fuzzy_select_prompt ( self . prompt . as_str ( ) , & search_term, position) ?;
@@ -240,16 +242,16 @@ impl FuzzySelect<'_> {
240
242
}
241
243
term. flush ( ) ?;
242
244
243
- match ( term. read_key ( ) ?, sel) {
244
- ( Key :: Escape , _) if allow_quit => {
245
- if self . clear {
246
- render. clear ( ) ?;
247
- term. flush ( ) ?;
248
- }
249
- term. show_cursor ( ) ?;
250
- return Ok ( None ) ;
245
+ match ( term. read_key ( ) ?, sel, vim_mode) {
246
+ ( Key :: Escape , _, false ) => {
247
+ vim_mode = true ;
248
+ }
249
+ ( Key :: Char ( 'i' | 'a' ) , _, true ) => {
250
+ vim_mode = false ;
251
251
}
252
- ( Key :: ArrowUp | Key :: BackTab , _) if !filtered_list. is_empty ( ) => {
252
+ ( Key :: ArrowUp | Key :: BackTab , _, _) | ( Key :: Char ( 'k' ) , _, true )
253
+ if !filtered_list. is_empty ( ) =>
254
+ {
253
255
if sel == Some ( 0 ) {
254
256
starting_row =
255
257
filtered_list. len ( ) . max ( visible_term_rows) - visible_term_rows;
@@ -266,7 +268,9 @@ impl FuzzySelect<'_> {
266
268
} ;
267
269
term. flush ( ) ?;
268
270
}
269
- ( Key :: ArrowDown | Key :: Tab , _) if !filtered_list. is_empty ( ) => {
271
+ ( Key :: ArrowDown | Key :: Tab , _, _) | ( Key :: Char ( 'j' ) , _, true )
272
+ if !filtered_list. is_empty ( ) =>
273
+ {
270
274
sel = match sel {
271
275
None => Some ( 0 ) ,
272
276
Some ( sel) => {
@@ -280,15 +284,17 @@ impl FuzzySelect<'_> {
280
284
}
281
285
term. flush ( ) ?;
282
286
}
283
- ( Key :: ArrowLeft , _) if position > 0 => {
287
+ ( Key :: ArrowLeft , _, _ ) | ( Key :: Char ( 'h' ) , _ , true ) if position > 0 => {
284
288
position -= 1 ;
285
289
term. flush ( ) ?;
286
290
}
287
- ( Key :: ArrowRight , _) if position < search_term. len ( ) => {
291
+ ( Key :: ArrowRight , _, _) | ( Key :: Char ( 'l' ) , _, true )
292
+ if position < search_term. len ( ) =>
293
+ {
288
294
position += 1 ;
289
295
term. flush ( ) ?;
290
296
}
291
- ( Key :: Enter , Some ( sel) ) if !filtered_list. is_empty ( ) => {
297
+ ( Key :: Enter , Some ( sel) , _ ) if !filtered_list. is_empty ( ) => {
292
298
if self . clear {
293
299
render. clear ( ) ?;
294
300
}
@@ -305,17 +311,18 @@ impl FuzzySelect<'_> {
305
311
term. show_cursor ( ) ?;
306
312
return Ok ( sel_string_pos_in_items) ;
307
313
}
308
- ( Key :: Backspace , _) if position > 0 => {
314
+ ( Key :: Backspace , _, _ ) if position > 0 => {
309
315
position -= 1 ;
310
316
search_term. remove ( position) ;
311
317
term. flush ( ) ?;
312
318
}
313
- ( Key :: Char ( chr) , _) if !chr. is_ascii_control ( ) => {
319
+ ( Key :: Char ( chr) , _, _ ) if !chr. is_ascii_control ( ) => {
314
320
search_term. insert ( position, chr) ;
315
321
position += 1 ;
316
322
term. flush ( ) ?;
317
323
sel = Some ( 0 ) ;
318
324
starting_row = 0 ;
325
+ vim_mode = false ;
319
326
}
320
327
321
328
_ => { }
0 commit comments