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.

agent_ui: Add keybindable action for terminal threads (#57399)

Ben Brandte024200c67e0
diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rs
index c99109a7d24..e52d0431bc2 100644
--- a/crates/agent_ui/src/agent_panel.rs
+++ b/crates/agent_ui/src/agent_panel.rs
@@ -38,9 +38,9 @@ use crate::terminal_thread_metadata_store::{TerminalThreadMetadata, TerminalThre
use crate::thread_metadata_store::{ThreadId, ThreadMetadataStore, ThreadMetadataStoreEvent};
use crate::{
AddContextServer, AgentDiffPane, ConversationView, CopyThreadToClipboard, Follow,
- LoadThreadFromClipboard, NewThread, OpenActiveThreadAsMarkdown, OpenAgentDiff,
- ResetTrialEndUpsell, ResetTrialUpsell, ShowAllSidebarThreadMetadata, ShowThreadMetadata,
- ToggleNewThreadMenu, ToggleOptionsMenu,
+ LoadThreadFromClipboard, NewTerminalThread, NewThread, OpenActiveThreadAsMarkdown,
+ OpenAgentDiff, ResetTrialEndUpsell, ResetTrialUpsell, ShowAllSidebarThreadMetadata,
+ ShowThreadMetadata, ToggleNewThreadMenu, ToggleOptionsMenu,
agent_configuration::{AgentConfiguration, AssistantConfigurationEvent},
conversation_view::{AcpThreadViewEvent, ThreadView},
ui::{AgentNotification, AgentNotificationEvent, EndTrialUpsell},
@@ -261,6 +261,19 @@ pub fn init(cx: &mut App) {
workspace.focus_panel::<AgentPanel>(window, cx);
}
})
+ .register_action(|workspace, _: &NewTerminalThread, window, cx| {
+ if let Some(panel) = workspace.panel::<AgentPanel>(cx) {
+ panel.update(cx, |panel, cx| {
+ panel.new_terminal(
+ Some(workspace),
+ AgentThreadSource::AgentPanel,
+ window,
+ cx,
+ )
+ });
+ workspace.focus_panel::<AgentPanel>(window, cx);
+ }
+ })
.register_action(
|workspace, action: &NewNativeAgentThreadFromSummary, window, cx| {
if let Some(panel) = workspace.panel::<AgentPanel>(cx) {
@@ -4989,6 +5002,9 @@ impl AgentPanel {
menu.item(
ContextMenuEntry::new("Terminal")
.when(showing_terminal, |this| this.action(Box::new(NewThread)))
+ .when(!showing_terminal, |this| {
+ this.action(Box::new(NewTerminalThread))
+ })
.icon(IconName::Terminal)
.icon_color(Color::Muted)
.handler({
@@ -5648,6 +5664,10 @@ impl Render for AgentPanel {
.on_action(cx.listener(|this, action: &NewThread, window, cx| {
this.new_thread(action, window, cx);
}))
+ .on_action(cx.listener(|this, _: &NewTerminalThread, window, cx| {
+ cx.stop_propagation();
+ this.new_terminal(None, AgentThreadSource::AgentPanel, window, cx);
+ }))
.on_action(cx.listener(|this, _: &OpenSettings, window, cx| {
this.open_configuration(window, cx);
}))
diff --git a/crates/agent_ui/src/agent_ui.rs b/crates/agent_ui/src/agent_ui.rs
index bb3fb26ac62..c9063378d89 100644
--- a/crates/agent_ui/src/agent_ui.rs
+++ b/crates/agent_ui/src/agent_ui.rs
@@ -244,6 +244,8 @@ actions!(
ScrollOutputToNextMessage,
/// Import agent threads from other Zed release channels (e.g. Preview, Nightly).
ImportThreadsFromOtherChannels,
+ /// Starts a new terminal thread.
+ NewTerminalThread,
]
);
@@ -850,6 +852,10 @@ mod tests {
!filter.is_hidden(&NewThread),
"NewThread should be visible by default"
);
+ assert!(
+ !filter.is_hidden(&NewTerminalThread),
+ "NewTerminalThread should be visible by default"
+ );
});
// Disable agent
@@ -869,6 +875,10 @@ mod tests {
filter.is_hidden(&NewThread),
"NewThread should be hidden when agent is disabled"
);
+ assert!(
+ filter.is_hidden(&NewTerminalThread),
+ "NewTerminalThread should be hidden when agent is disabled"
+ );
});
// Test EditPredictionProvider
diff --git a/crates/sidebar/src/sidebar.rs b/crates/sidebar/src/sidebar.rs
index 1dfec54ebaa..199c453d092 100644
--- a/crates/sidebar/src/sidebar.rs
+++ b/crates/sidebar/src/sidebar.rs
@@ -17,8 +17,8 @@ use agent_ui::threads_archive_view::{
};
use agent_ui::{
AcpThreadImportOnboarding, Agent, AgentPanel, AgentPanelEvent, AgentThreadSource,
- ArchiveSelectedThread, CrossChannelImportOnboarding, DEFAULT_THREAD_TITLE, NewThread,
- TerminalId, ThreadId, ThreadImportModal, channels_with_threads,
+ ArchiveSelectedThread, CrossChannelImportOnboarding, DEFAULT_THREAD_TITLE, NewTerminalThread,
+ NewThread, TerminalId, ThreadId, ThreadImportModal, channels_with_threads,
import_threads_from_other_channels,
};
use chrono::{DateTime, Utc};
@@ -107,6 +107,12 @@ enum SerializedSidebarView {
History,
}
+#[derive(Clone, Copy)]
+enum NewEntryTarget {
+ LastCreatedKind,
+ Terminal,
+}
+
#[derive(Default, Serialize, Deserialize)]
struct SerializedSidebar {
#[serde(default)]
@@ -1130,6 +1136,7 @@ impl Sidebar {
fn open_workspace_and_create_entry(
&mut self,
project_group_key: &ProjectGroupKey,
+ target: NewEntryTarget,
window: &mut Window,
cx: &mut Context<Self>,
) {
@@ -1158,8 +1165,9 @@ impl Sidebar {
cx.spawn_in(window, async move |this, cx| {
let workspace = task.await?;
- this.update_in(cx, |this, window, cx| {
- this.create_new_entry(&workspace, window, cx);
+ this.update_in(cx, |this, window, cx| match target {
+ NewEntryTarget::LastCreatedKind => this.create_new_entry(&workspace, window, cx),
+ NewEntryTarget::Terminal => this.create_new_terminal(&workspace, window, cx),
})?;
anyhow::Ok(())
})
@@ -2092,7 +2100,12 @@ impl Sidebar {
if let Some(workspace) = this.workspace_for_group(&key, cx) {
this.create_new_entry(&workspace, window, cx);
} else {
- this.open_workspace_and_create_entry(&key, window, cx);
+ this.open_workspace_and_create_entry(
+ &key,
+ NewEntryTarget::LastCreatedKind,
+ window,
+ cx,
+ );
}
},
))
@@ -5578,13 +5591,39 @@ impl Sidebar {
if let Some(workspace) = self.workspace_for_group(&key, cx) {
self.create_new_entry(&workspace, window, cx);
} else {
- self.open_workspace_and_create_entry(&key, window, cx);
+ self.open_workspace_and_create_entry(
+ &key,
+ NewEntryTarget::LastCreatedKind,
+ window,
+ cx,
+ );
}
} else if let Some(workspace) = self.active_workspace(cx) {
self.create_new_entry(&workspace, window, cx);
}
}
+ fn new_terminal_thread(
+ &mut self,
+ _: &NewTerminalThread,
+ window: &mut Window,
+ cx: &mut Context<Self>,
+ ) {
+ cx.stop_propagation();
+
+ if let Some(key) = self.selected_group_key() {
+ self.set_group_expanded(&key, true, cx);
+ self.selection = None;
+ if let Some(workspace) = self.workspace_for_group(&key, cx) {
+ self.create_new_terminal(&workspace, window, cx);
+ } else {
+ self.open_workspace_and_create_entry(&key, NewEntryTarget::Terminal, window, cx);
+ }
+ } else if let Some(workspace) = self.active_workspace(cx) {
+ self.create_new_terminal(&workspace, window, cx);
+ }
+ }
+
/// Closed linked-worktree drafts need an open workspace so archive root
/// planning can inspect repositories before deleting the worktree.
fn open_workspace_and_remove_draft(
@@ -6794,6 +6833,7 @@ impl Render for Sidebar {
.on_action(cx.listener(Self::cancel))
.on_action(cx.listener(Self::archive_selected_thread))
.on_action(cx.listener(Self::new_thread_in_group))
+ .on_action(cx.listener(Self::new_terminal_thread))
.on_action(cx.listener(Self::toggle_archive))
.on_action(cx.listener(Self::focus_sidebar_filter))
.on_action(cx.listener(Self::on_toggle_thread_switcher))