@@ -20,12 +20,26 @@ pub struct NxShellOptions {
20
20
pub show_add_session_modal : Rc < RefCell < bool > > ,
21
21
pub show_dock_panel : bool ,
22
22
pub multi_exec : bool ,
23
+ /// Id of active tab
24
+ ///
25
+ /// Its main purpose is to preserve the state of egui::Response::contains_pointer().
26
+ /// Its functions :
27
+ ///
28
+ /// 1. When the mouse cursor leaves the terminal, it still influences the state of the current
29
+ /// terminal's selection.
30
+ /// 2. When it is None, all tabs lose focus, and you can iteract with the other UI components.
23
31
pub active_tab_id : Option < Id > ,
24
32
pub term_font : TerminalFont ,
25
33
pub term_font_size : f32 ,
26
34
pub session_filter : String ,
27
35
}
28
36
37
+ impl NxShellOptions {
38
+ pub fn surrender_focus ( & mut self ) {
39
+ self . active_tab_id = None ;
40
+ }
41
+ }
42
+
29
43
impl Default for NxShellOptions {
30
44
fn default ( ) -> Self {
31
45
let term_font_size = 14. ;
@@ -130,13 +144,14 @@ impl eframe::App for NxShell {
130
144
} ) ;
131
145
132
146
if * self . opts . show_add_session_modal . borrow ( ) {
147
+ self . opts . surrender_focus ( ) ;
133
148
self . show_add_session_window ( ctx, & mut toasts) ;
134
- } else {
135
- egui:: CentralPanel :: default ( ) . show ( ctx, |_ui| {
136
- self . tab_view ( ctx) ;
137
- } ) ;
138
149
}
139
150
151
+ egui:: CentralPanel :: default ( ) . show ( ctx, |_ui| {
152
+ self . tab_view ( ctx) ;
153
+ } ) ;
154
+
140
155
toasts. show ( ctx) ;
141
156
}
142
157
}
@@ -146,8 +161,7 @@ impl NxShell {
146
161
let text_edit = TextEdit :: singleline ( & mut self . opts . session_filter ) ;
147
162
let response = ui. add ( text_edit) ;
148
163
if response. clicked ( ) {
149
- // gain ui focus
150
- self . opts . active_tab_id = None ;
164
+ self . opts . surrender_focus ( ) ;
151
165
} else if response. changed ( ) {
152
166
if let Ok ( sessions) = self . db . find_sessions ( & self . opts . session_filter ) {
153
167
self . state_manager . sessions = Some ( sessions) ;
0 commit comments