Skip to content

Commit ee120eb

Browse files
authored
fix: unable to interact with the session window upon launching the terminal (#13)
1 parent 1281c6c commit ee120eb

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

nxshell/src/app.rs

+20-6
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,26 @@ pub struct NxShellOptions {
2020
pub show_add_session_modal: Rc<RefCell<bool>>,
2121
pub show_dock_panel: bool,
2222
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.
2331
pub active_tab_id: Option<Id>,
2432
pub term_font: TerminalFont,
2533
pub term_font_size: f32,
2634
pub session_filter: String,
2735
}
2836

37+
impl NxShellOptions {
38+
pub fn surrender_focus(&mut self) {
39+
self.active_tab_id = None;
40+
}
41+
}
42+
2943
impl Default for NxShellOptions {
3044
fn default() -> Self {
3145
let term_font_size = 14.;
@@ -130,13 +144,14 @@ impl eframe::App for NxShell {
130144
});
131145

132146
if *self.opts.show_add_session_modal.borrow() {
147+
self.opts.surrender_focus();
133148
self.show_add_session_window(ctx, &mut toasts);
134-
} else {
135-
egui::CentralPanel::default().show(ctx, |_ui| {
136-
self.tab_view(ctx);
137-
});
138149
}
139150

151+
egui::CentralPanel::default().show(ctx, |_ui| {
152+
self.tab_view(ctx);
153+
});
154+
140155
toasts.show(ctx);
141156
}
142157
}
@@ -146,8 +161,7 @@ impl NxShell {
146161
let text_edit = TextEdit::singleline(&mut self.opts.session_filter);
147162
let response = ui.add(text_edit);
148163
if response.clicked() {
149-
// gain ui focus
150-
self.opts.active_tab_id = None;
164+
self.opts.surrender_focus();
151165
} else if response.changed() {
152166
if let Ok(sessions) = self.db.find_sessions(&self.opts.session_filter) {
153167
self.state_manager.sessions = Some(sessions);

nxshell/src/ui/form/session.rs

+11
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,17 @@ impl NxShell {
174174
auth,
175175
},
176176
};
177+
178+
if self
179+
.db
180+
.find_session(&session.group, &session.name)?
181+
.is_some()
182+
{
183+
return Err(NxError::Plain(
184+
"`group` and `name` already exist, please choose another name.".to_string(),
185+
));
186+
}
187+
177188
self.add_shell_tab(ctx.clone(), typ)?;
178189

179190
self.db.insert_session(Session {

0 commit comments

Comments
 (0)