Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

terminal: Fix unresponsive buttons on load until center pane is clicked + Auto-focus docked terminal on load if no other item is focused (#23039)

tims7ed834bd79c6
diff --git a/crates/terminal_view/src/persistence.rs b/crates/terminal_view/src/persistence.rs
index a3bb2cc522b..36b07bdd6dd 100644
--- a/crates/terminal_view/src/persistence.rs
+++ b/crates/terminal_view/src/persistence.rs
@@ -146,13 +146,16 @@ fn populate_pane_items(
cx: &mut ViewContext<Pane>,
) {
let mut item_index = pane.items_len();
+ let mut active_item_index = None;
for item in items {
- let activate_item = Some(item.item_id().as_u64()) == active_item;
+ if Some(item.item_id().as_u64()) == active_item {
+ active_item_index = Some(item_index);
+ }
pane.add_item(Box::new(item), false, false, None, cx);
item_index += 1;
- if activate_item {
- pane.activate_item(item_index, false, false, cx);
- }
+ }
+ if let Some(index) = active_item_index {
+ pane.activate_item(index, false, false, cx);
}
}
diff --git a/crates/terminal_view/src/terminal_panel.rs b/crates/terminal_view/src/terminal_panel.rs
index a250d3bcadc..5f3b9d336aa 100644
--- a/crates/terminal_view/src/terminal_panel.rs
+++ b/crates/terminal_view/src/terminal_panel.rs
@@ -31,7 +31,7 @@ use ui::{
};
use util::{ResultExt, TryFutureExt};
use workspace::{
- dock::{DockPosition, Panel, PanelEvent},
+ dock::{DockPosition, Panel, PanelEvent, PanelHandle},
item::SerializableItem,
move_active_item, move_item, pane,
ui::IconName,
@@ -83,7 +83,6 @@ impl TerminalPanel {
let project = workspace.project();
let pane = new_terminal_pane(workspace.weak_handle(), project.clone(), false, cx);
let center = PaneGroup::new(pane.clone());
- cx.focus_view(&pane);
let terminal_panel = Self {
center,
active_pane: pane,
@@ -283,6 +282,25 @@ impl TerminalPanel {
}
}
+ if let Some(workspace) = workspace.upgrade() {
+ let should_focus = workspace
+ .update(&mut cx, |workspace, cx| {
+ workspace.active_item(cx).is_none()
+ && workspace.is_dock_at_position_open(terminal_panel.position(cx), cx)
+ })
+ .unwrap_or(false);
+
+ if should_focus {
+ terminal_panel
+ .update(&mut cx, |panel, cx| {
+ panel.active_pane.update(cx, |pane, cx| {
+ pane.focus_active_item(cx);
+ });
+ })
+ .ok();
+ }
+ }
+
Ok(terminal_panel)
}
diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs
index bc5d801e06a..e4488650ec3 100644
--- a/crates/workspace/src/workspace.rs
+++ b/crates/workspace/src/workspace.rs
@@ -2298,6 +2298,19 @@ impl Workspace {
}
}
+ pub fn is_dock_at_position_open(
+ &self,
+ position: DockPosition,
+ cx: &mut ViewContext<Self>,
+ ) -> bool {
+ let dock = match position {
+ DockPosition::Left => &self.left_dock,
+ DockPosition::Bottom => &self.bottom_dock,
+ DockPosition::Right => &self.right_dock,
+ };
+ dock.read(cx).is_open()
+ }
+
pub fn toggle_dock(&mut self, dock_side: DockPosition, cx: &mut ViewContext<Self>) {
let dock = match dock_side {
DockPosition::Left => &self.left_dock,