@@ -169,20 +169,21 @@ impl SourceContext {
169169}
170170
171171#[ derive( Debug , Clone ) ]
172- pub enum CurrentView {
172+ pub enum SelectedView {
173173 Listen ,
174174 Session ,
175175 Help ,
176176}
177177
178178pub struct App {
179- pub is_connected : bool ,
180- pub notification : Notification ,
181- pub config : Config ,
182179 receiver : Receiver < AppEvent > ,
183180 quit : bool ,
184181 sender : Sender < AppEvent > ,
185182
183+ pub is_connected : bool ,
184+ pub notification : Notification ,
185+ pub config : Config ,
186+
186187 pub server_status : Option < ContinuationStatus > ,
187188 pub command_input : Input ,
188189 pub command_response : Option < String > ,
@@ -191,7 +192,8 @@ pub struct App {
191192
192193 pub history : History ,
193194
194- pub view_current : CurrentView ,
195+ pub view_current : SelectedView ,
196+ pub focus_view : bool ,
195197 pub session_view : SessionViewState ,
196198 pub input_plurality : Vec < char > ,
197199
@@ -229,7 +231,8 @@ impl App {
229231 server_status : None ,
230232 command_input : Input :: default ( ) ,
231233 command_response : None ,
232- view_current : CurrentView :: Listen ,
234+ view_current : SelectedView :: Listen ,
235+ focus_view : false ,
233236 session_view : SessionViewState :: new ( ) ,
234237
235238 snapshot_notify : Arc :: new ( Notify :: new ( ) ) ,
@@ -401,6 +404,14 @@ impl App {
401404 . feature_set ( "max_depth" , self . context_depth . to_string ( ) . as_str ( ) )
402405 . await ?;
403406 }
407+ AppEvent :: ContextFilterOpen => {
408+ self . session_view . context_filter . show = true ;
409+ self . focus_view = true ;
410+ } ,
411+ AppEvent :: ContextSearchClose => {
412+ self . session_view . context_filter . show = false ;
413+ self . focus_view = false ;
414+ } ,
404415 AppEvent :: ScrollSource ( amount) => {
405416 self . session_view . source_scroll = apply_scroll (
406417 self . session_view . source_scroll ,
@@ -440,19 +451,27 @@ impl App {
440451 . await ?;
441452 }
442453 AppEvent :: PushInputPlurality ( char) => self . input_plurality . push ( char) ,
443- AppEvent :: Input ( key_event) => match key_event. code {
444- KeyCode :: Char ( 't' ) => {
445- self . theme = self . theme . next ( ) ;
446- self . notification =
447- Notification :: info ( format ! ( "Switched to theme: {:?}" , self . theme) ) ;
448- }
449- KeyCode :: Char ( '?' ) => {
450- self . sender
451- . send ( AppEvent :: ChangeView ( CurrentView :: Help ) )
452- . await
453- . unwrap ( ) ;
454+ AppEvent :: Input ( key_event) => {
455+ if self . focus_view {
456+ // event shandled exclusively by view (e.g. input needs focus)
457+ self . send_event_to_current_view ( event) . await ;
458+ } else {
459+ // global events
460+ match key_event. code {
461+ KeyCode :: Char ( 't' ) => {
462+ self . theme = self . theme . next ( ) ;
463+ self . notification =
464+ Notification :: info ( format ! ( "Switched to theme: {:?}" , self . theme) ) ;
465+ }
466+ KeyCode :: Char ( '?' ) => {
467+ self . sender
468+ . send ( AppEvent :: ChangeView ( SelectedView :: Help ) )
469+ . await
470+ . unwrap ( ) ;
471+ }
472+ _ => self . send_event_to_current_view ( event) . await ,
473+ }
454474 }
455- _ => self . send_event_to_current_view ( event) . await ,
456475 } ,
457476 _ => self . send_event_to_current_view ( event) . await ,
458477 } ;
@@ -520,9 +539,9 @@ impl App {
520539 // route the event to the currently selected view
521540 async fn send_event_to_current_view ( & mut self , event : AppEvent ) {
522541 let subsequent_event = match self . view_current {
523- CurrentView :: Help => HelpView :: handle ( self , event) ,
524- CurrentView :: Listen => ListenView :: handle ( self , event) ,
525- CurrentView :: Session => SessionView :: handle ( self , event) ,
542+ SelectedView :: Help => HelpView :: handle ( self , event) ,
543+ SelectedView :: Listen => ListenView :: handle ( self , event) ,
544+ SelectedView :: Session => SessionView :: handle ( self , event) ,
526545 } ;
527546 if let Some ( event) = subsequent_event {
528547 self . sender . send ( event) . await . unwrap ( )
@@ -611,7 +630,7 @@ impl App {
611630
612631 fn reset ( & mut self ) {
613632 self . server_status = None ;
614- self . view_current = CurrentView :: Session ;
633+ self . view_current = SelectedView :: Session ;
615634 self . session_view . mode = SessionViewMode :: Current ;
616635 self . analyzed_files = HashMap :: new ( ) ;
617636 self . workspace . reset ( ) ;
0 commit comments