@@ -38,6 +38,7 @@ pub struct FuzzySelect<'a> {
38
38
report : bool ,
39
39
clear : bool ,
40
40
highlight_matches : bool ,
41
+ enable_vim_mode : bool ,
41
42
max_length : Option < usize > ,
42
43
theme : & ' a dyn Theme ,
43
44
/// Search string that a fuzzy search with start with.
@@ -118,6 +119,17 @@ impl FuzzySelect<'_> {
118
119
self
119
120
}
120
121
122
+ /// Indicated whether to allow the use of vim mode
123
+ ///
124
+ /// Vim mode can be entered by pressing Escape.
125
+ /// This then allows the user to navigate using hjkl.
126
+ ///
127
+ /// The default is to disable vim mode.
128
+ pub fn enable_vim_mode ( mut self , val : bool ) -> Self {
129
+ self . enable_vim_mode = val;
130
+ self
131
+ }
132
+
121
133
/// Sets the maximum number of visible options.
122
134
///
123
135
/// The default is the height of the terminal minus 2.
@@ -243,7 +255,15 @@ impl FuzzySelect<'_> {
243
255
term. flush ( ) ?;
244
256
245
257
match ( term. read_key ( ) ?, sel, vim_mode) {
246
- ( Key :: Escape , _, false ) => {
258
+ ( Key :: Escape , _, _) if allow_quit && !self . enable_vim_mode => {
259
+ if self . clear {
260
+ render. clear ( ) ?;
261
+ term. flush ( ) ?;
262
+ }
263
+ term. show_cursor ( ) ?;
264
+ return Ok ( None ) ;
265
+ }
266
+ ( Key :: Escape , _, false ) if self . enable_vim_mode => {
247
267
vim_mode = true ;
248
268
}
249
269
( Key :: Char ( 'i' | 'a' ) , _, true ) => {
@@ -356,6 +376,7 @@ impl<'a> FuzzySelect<'a> {
356
376
report : true ,
357
377
clear : true ,
358
378
highlight_matches : true ,
379
+ enable_vim_mode : false ,
359
380
max_length : None ,
360
381
theme,
361
382
initial_text : "" . into ( ) ,
0 commit comments