fix(session): 移除连接断开询问弹窗,保留并优化红色悬浮行与回车重连交互

This commit is contained in:
TomZz
2026-11-08 12:51:01 +08:00
parent b60c5c4b04
commit d6a5d93eaf
4 changed files with 3 additions and 161 deletions
-128
View File
@@ -1556,134 +1556,6 @@ impl Ashell {
});
}
pub(crate) fn prompt_active_ssh_reconnect_if_needed(
&mut self,
window: &mut Window,
cx: &mut Context<Self>,
) {
let Some(tab_id) = self.active_tab.as_ref().and_then(|active_tab_id| {
self.tabs
.iter()
.find(|tab| {
tab.id == *active_tab_id
&& tab.kind == crate::terminal::TabKind::Ssh
&& !tab.connected
&& tab.disconnected_reason.is_some()
&& tab.session.is_some()
})
.map(|tab| tab.id.clone())
}) else {
return;
};
self.show_ssh_reconnect_dialog(tab_id, window, cx);
}
pub(crate) fn show_ssh_reconnect_dialog(
&mut self,
tab_id: String,
window: &mut Window,
cx: &mut Context<Self>,
) {
if self.active_dialog.is_some()
|| self.active_tab.as_deref() != Some(tab_id.as_str())
|| !self.tabs.iter().any(|tab| {
tab.id == tab_id
&& tab.kind == crate::terminal::TabKind::Ssh
&& !tab.connected
&& tab.disconnected_reason.is_some()
&& tab.session.is_some()
})
{
return;
}
let session_name = self
.tabs
.iter()
.find(|tab| tab.id == tab_id)
.map(|tab| tab.title.clone())
.unwrap_or_else(|| tab_id.clone());
let view = cx.entity();
self.active_dialog = Some(crate::app::DialogKind::SshReconnect);
window.open_dialog(cx, move |dialog: Dialog, _window, _| {
dialog
.title(t!("reconnect_ssh_title").to_string())
.w(px(400.))
.keyboard(false)
.on_close({
let view = view.clone();
move |_, _, cx| {
view.update(cx, |this, cx| {
if this.active_dialog == Some(crate::app::DialogKind::SshReconnect) {
this.active_dialog = None;
}
cx.notify();
});
}
})
.content({
let session_name = session_name.clone();
move |content, _window, _cx| {
content.child(
div()
.w_full()
.whitespace_normal()
.text_size(ui_rems(0.917))
.child(
t!("reconnect_ssh_desc", name = session_name.as_str())
.to_string(),
),
)
}
})
.footer({
let view = view.clone();
let tab_id = tab_id.clone();
h_flex()
.w_full()
.justify_end()
.gap_2()
.child(
pointer_button("ssh-reconnect-cancel")
.ghost()
.label(t!("cancel").to_string())
.on_click({
let view = view.clone();
move |_, window, cx| {
view.update(cx, |this, cx| {
if this.active_dialog
== Some(crate::app::DialogKind::SshReconnect)
{
this.active_dialog = None;
}
cx.notify();
});
window.close_dialog(cx);
}
}),
)
.child(
pointer_button("ssh-reconnect-confirm")
.primary()
.label(t!("reconnect_ssh").to_string())
.on_click(move |_, window, cx| {
view.update(cx, |this, cx| {
if this.active_dialog
== Some(crate::app::DialogKind::SshReconnect)
{
this.active_dialog = None;
}
this.retry_disconnected_tab(&tab_id, cx);
});
window.close_dialog(cx);
}),
)
})
});
}
pub(crate) fn show_connection_group_dialog(
&mut self,
group: Option<String>,
-1
View File
@@ -255,7 +255,6 @@ pub(crate) enum DialogKind {
SftpEditor,
Processes,
Ports,
SshReconnect,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
+2 -6
View File
@@ -5221,13 +5221,8 @@ impl Ashell {
.when(is_url_hovered, |d| d.cursor_pointer())
.on_mouse_down(
MouseButton::Left,
cx.listener(move |this, _, window, cx| {
let active_tab_changed =
this.active_tab.as_deref() != Some(tab_id_clone2.as_str());
cx.listener(move |this, _, _, cx| {
this.focus_pane_with_id(tab_id_clone2.clone());
if active_tab_changed {
this.prompt_active_ssh_reconnect_if_needed(window, cx);
}
cx.notify();
}),
)
@@ -5291,6 +5286,7 @@ impl Ashell {
.on_mouse_down(
MouseButton::Left,
cx.listener(move |this, _, _, cx| {
this.focus_pane_with_id(tab_id_for_reconnect.clone());
this.retry_disconnected_tab(&tab_id_for_reconnect, cx);
}),
),
+1 -26
View File
@@ -302,7 +302,7 @@ impl Ashell {
}
}
pub(crate) fn restore_saved_tabs(&mut self, window: &mut Window, cx: &mut Context<Self>) {
pub(crate) fn restore_saved_tabs(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
if !self.config.remember_tabs() {
return;
}
@@ -481,23 +481,6 @@ impl Ashell {
self.sync_sftp_to_active_tab();
self.sync_system_tab_to_active_group();
self.status = "tabs restored".into();
// Defer the dialog until the restored view has been mounted. This also
// ensures that only the currently focused restored SSH tab is prompted.
let prompt_tab_id = self.active_tab.as_ref().and_then(|tab_id| {
self.tabs
.iter()
.find(|tab| tab.id == *tab_id && tab.kind == TabKind::Ssh && !tab.connected)
.map(|tab| tab.id.clone())
});
if let Some(prompt_tab_id) = prompt_tab_id {
let view = cx.entity();
window.defer(cx, move |window, cx| {
view.update(cx, |this, cx| {
this.show_ssh_reconnect_dialog(prompt_tab_id, window, cx);
});
});
}
cx.notify();
}
@@ -1794,7 +1777,6 @@ impl Ashell {
pub(crate) fn activate_tab(&mut self, id: String, window: &mut Window, cx: &mut Context<Self>) {
let previous_active_tab = self.active_tab.clone();
let active_tab_changed = previous_active_tab.as_deref() != Some(id.as_str());
// Save current group state
if let Some(group_id) = self.active_group.clone() {
if let Some(group) = self.tab_groups.iter_mut().find(|g| g.id == group_id) {
@@ -1839,9 +1821,6 @@ impl Ashell {
self.sync_system_tab_to_active_group();
self.update_terminal_focus(previous_active_tab.as_deref());
self.save_tabs_state_background();
if active_tab_changed {
self.prompt_active_ssh_reconnect_if_needed(window, cx);
}
cx.notify();
}
@@ -2349,7 +2328,6 @@ impl Ashell {
}
if active_tab_changed {
self.update_terminal_focus(previous_active_tab.as_deref());
self.prompt_active_ssh_reconnect_if_needed(window, cx);
}
}
@@ -2492,9 +2470,6 @@ impl Ashell {
self.sync_system_tab_to_active_group();
self.update_terminal_focus(previous_active_tab.as_deref());
self.save_tabs_state_background();
if previous_active_tab != self.active_tab {
self.prompt_active_ssh_reconnect_if_needed(window, cx);
}
cx.notify();
}