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: Do not show workspace actions in agent panel terminals (#60072)

Bennet Bo Fenner031ccfd736ae
diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rs
index a26935e8591..209a2e0fe0b 100644
--- a/crates/agent_ui/src/agent_panel.rs
+++ b/crates/agent_ui/src/agent_panel.rs
@@ -2044,7 +2044,10 @@ impl AgentPanel {
this.update_in(cx, |this, window, cx| {
let terminal_for_init_command = terminal.clone();
let terminal_view = cx.new(|cx| {
- TerminalView::new(terminal, workspace, workspace_id, project, window, cx)
+ let mut view =
+ TerminalView::new(terminal, workspace, workspace_id, project, window, cx);
+ view.set_show_workspace_actions(false, cx);
+ view
});
this.insert_terminal(
terminal_id,
@@ -4070,6 +4073,13 @@ impl AgentPanel {
}
}
+ pub fn visible_terminal_view(&self) -> Option<&Entity<TerminalView>> {
+ match self.visible_surface() {
+ VisibleSurface::Terminal(terminal_view) => Some(terminal_view),
+ _ => None,
+ }
+ }
+
pub fn conversation_view_for_id(
&self,
thread_id: &ThreadId,
@@ -6866,14 +6876,16 @@ impl AgentPanel {
let terminal = cx.new(|cx| builder.subscribe(cx));
let terminal_for_init_command = terminal.clone();
let terminal_view = cx.new(|cx| {
- TerminalView::new(
+ let mut view = TerminalView::new(
terminal,
self.workspace.clone(),
self.workspace_id,
self.project.downgrade(),
window,
cx,
- )
+ );
+ view.set_show_workspace_actions(false, cx);
+ view
});
self.insert_terminal(
terminal_id,
diff --git a/crates/agent_ui/src/inline_assistant.rs b/crates/agent_ui/src/inline_assistant.rs
index 4790b72fb92..bec734527b8 100644
--- a/crates/agent_ui/src/inline_assistant.rs
+++ b/crates/agent_ui/src/inline_assistant.rs
@@ -1476,6 +1476,13 @@ impl InlineAssistant {
return Some(InlineAssistTarget::Terminal(terminal_view));
}
+ if let Some(agent_panel) = workspace.panel::<AgentPanel>(cx)
+ && let Some(terminal_view) = agent_panel.read(cx).visible_terminal_view().cloned()
+ && terminal_view.focus_handle(cx).contains_focused(window, cx)
+ {
+ return Some(InlineAssistTarget::Terminal(terminal_view));
+ }
+
if let Some(workspace_editor) = workspace
.active_item(cx)
.and_then(|item| item.act_as::<Editor>(cx))
diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs
index 9c4321ca691..6511497623a 100644
--- a/crates/terminal_view/src/terminal_view.rs
+++ b/crates/terminal_view/src/terminal_view.rs
@@ -138,6 +138,9 @@ pub struct TerminalView {
cursor_shape: CursorShape,
blink_manager: Entity<BlinkManager>,
mode: TerminalMode,
+ // Explicit override for whether workspace-specific context menu actions are shown.
+ // When `None`, visibility is derived from `mode` (hidden for embedded terminals).
+ show_workspace_actions: Option<bool>,
blinking_terminal_enabled: bool,
needs_serialize: bool,
custom_title: Option<String>,
@@ -287,6 +290,7 @@ impl TerminalView {
hover: None,
hover_tooltip_update: Task::ready(()),
mode: TerminalMode::Standalone,
+ show_workspace_actions: None,
workspace_id,
show_breadcrumbs: TerminalSettings::get_global(cx).toolbar.breadcrumbs,
block_below_cursor: None,
@@ -315,6 +319,22 @@ impl TerminalView {
cx.notify();
}
+ /// Explicitly override whether workspace-specific context menu actions (e.g. creating or
+ /// closing terminal tabs, inline assist) are shown.
+ ///
+ /// This lets hosts that aren't workspace panes (such as the agent panel) hide these
+ /// actions without `terminal_view` needing to know about those hosts. When never called,
+ /// visibility is derived from the terminal's `mode`.
+ pub fn set_show_workspace_actions(&mut self, show: bool, cx: &mut Context<Self>) {
+ self.show_workspace_actions = Some(show);
+ cx.notify();
+ }
+
+ fn shows_workspace_actions(&self) -> bool {
+ self.show_workspace_actions
+ .unwrap_or_else(|| !matches!(self.mode, TerminalMode::Embedded { .. }))
+ }
+
const MAX_EMBEDDED_LINES: usize = 1_000;
/// Returns the current `ContentMode` depending on the set `TerminalMode` and the current number of lines
@@ -507,35 +527,46 @@ impl TerminalView {
.is_some_and(|terminal_panel| terminal_panel.read(cx).assistant_enabled());
let context_menu = ContextMenu::build(window, cx, |menu, _, _| {
menu.context(self.focus_handle.clone())
- .action("New Terminal", Box::new(NewTerminal::default()))
- .action(
- "New Center Terminal",
- Box::new(NewCenterTerminal::default()),
- )
- .separator()
+ .when(self.shows_workspace_actions(), |menu| {
+ menu.action("New Terminal", Box::new(NewTerminal::default()))
+ .action(
+ "New Center Terminal",
+ Box::new(NewCenterTerminal::default()),
+ )
+ .separator()
+ })
.action("Copy", Box::new(Copy))
- .action("Paste", Box::new(Paste))
- .action("Paste Text", Box::new(PasteText))
+ .when(
+ !matches!(self.mode, TerminalMode::Embedded { .. }),
+ |menu| {
+ menu.action("Paste", Box::new(Paste))
+ .action("Paste Text", Box::new(PasteText))
+ },
+ )
.action("Select All", Box::new(SelectAll))
- .action("Clear", Box::new(Clear))
+ .when(
+ !matches!(self.mode, TerminalMode::Embedded { .. }),
+ |menu| menu.action("Clear", Box::new(Clear)),
+ )
.when(
assistant_enabled && !matches!(self.mode, TerminalMode::Embedded { .. }),
|menu| {
menu.separator()
.action("Inline Assist", Box::new(InlineAssist::default()))
- .when(has_selection, |menu| {
+ .when(has_selection && self.shows_workspace_actions(), |menu| {
menu.action("Add to Agent Thread", Box::new(AddSelectionToThread))
})
},
)
- .separator()
- .action(
- "Close Terminal Tab",
- Box::new(CloseActiveItem {
- save_intent: None,
- close_pinned: true,
- }),
- )
+ .when(self.shows_workspace_actions(), |menu| {
+ menu.separator().action(
+ "Close Terminal Tab",
+ Box::new(CloseActiveItem {
+ save_intent: None,
+ close_pinned: true,
+ }),
+ )
+ })
});
window.focus(&context_menu.focus_handle(cx), cx);