@@ -347,6 +347,14 @@ impl<Engine: BrowserEngine> IcyBrowser<Engine> {
347
347
} ) = event
348
348
{
349
349
match key {
350
+ key:: Key :: Named ( key:: Named :: Escape ) => {
351
+ self . command_window_state . query = String :: new ( ) ;
352
+ self . command_window_state . filtered_results =
353
+ self . command_window_state . possible_results . clone ( ) ;
354
+ self . command_window_state . selected_item = None ;
355
+
356
+ Task :: done ( Message :: HideOverlay )
357
+ }
350
358
key:: Key :: Named ( key:: Named :: ArrowDown ) => {
351
359
self . command_window_state . next_item ( ) ;
352
360
Task :: none ( )
@@ -355,8 +363,66 @@ impl<Engine: BrowserEngine> IcyBrowser<Engine> {
355
363
self . command_window_state . previous_item ( ) ;
356
364
Task :: none ( )
357
365
}
358
- // key::Key::Character(_) => todo!(),
359
- // key::Key::Unidentified => todo!(),
366
+ key:: Key :: Named ( key:: Named :: Backspace ) => {
367
+ self . command_window_state . next_item ( ) ;
368
+ if self . command_window_state . query . is_empty ( ) {
369
+ Task :: none ( )
370
+ } else {
371
+ Task :: done ( Message :: CommandPalatteQueryChanged (
372
+ self . command_window_state . query
373
+ [ ..self . command_window_state . query . len ( ) - 1 ]
374
+ . to_string ( ) ,
375
+ ) )
376
+ }
377
+ }
378
+ key:: Key :: Named ( key:: Named :: Space ) => {
379
+ self . command_window_state . next_item ( ) ;
380
+ Task :: done ( Message :: CommandPalatteQueryChanged ( format ! (
381
+ "{} " ,
382
+ self . command_window_state. query
383
+ ) ) )
384
+ }
385
+ key:: Key :: Character ( char) => {
386
+ self . command_window_state . next_item ( ) ;
387
+ Task :: done ( Message :: CommandPalatteQueryChanged ( format ! (
388
+ "{}{}" ,
389
+ self . command_window_state. query, char
390
+ ) ) )
391
+ }
392
+ key:: Key :: Named ( key:: Named :: Enter ) => {
393
+ for result in & self . command_window_state . filtered_results {
394
+ if let Some ( selected_item) =
395
+ & self . command_window_state . selected_item
396
+ {
397
+ if result. inner_name ( ) == * selected_item {
398
+ let task = match result {
399
+ ResultType :: Commands ( message) => message. clone ( ) ,
400
+ ResultType :: Bookmarks ( bookmark) => {
401
+ Message :: GoToUrl ( bookmark. url ( ) . to_string ( ) )
402
+ }
403
+ } ;
404
+
405
+ self . command_window_state . query = String :: new ( ) ;
406
+ self . command_window_state . filtered_results =
407
+ self . command_window_state . possible_results . clone ( ) ;
408
+ self . command_window_state . selected_item = None ;
409
+
410
+ return Task :: batch ( [
411
+ Task :: done ( task) ,
412
+ Task :: done ( Message :: HideOverlay ) ,
413
+ ] ) ;
414
+ }
415
+ }
416
+ }
417
+ // TODO: maybe make red to show none was selected
418
+ self . command_window_state . query = String :: new ( ) ;
419
+ self . command_window_state . filtered_results =
420
+ self . command_window_state . possible_results . clone ( ) ;
421
+ self . command_window_state . selected_item = None ;
422
+
423
+ Task :: done ( Message :: HideOverlay )
424
+ }
425
+
360
426
_ => Task :: none ( ) ,
361
427
}
362
428
} else {
0 commit comments