Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
agent_ui: Remove redundant non-empty check (#64589)
Neel18ad8d11958c
diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rsindex 4efc64b6526..064faad4309 100644--- a/crates/agent_ui/src/agent_panel.rs+++ b/crates/agent_ui/src/agent_panel.rs@@ -83,12 +83,13 @@ use language::LanguageRegistry;use language_model::LanguageModelRegistry;use notifications::status_toast::StatusToast;use project::{Project, ProjectPath, Worktree};-use settings::TerminalDockPosition;use settings::{NotifyWhenAgentWaiting, Settings, update_settings_file};use search::{BufferSearchBar, buffer_search::Deploy as DeployBufferSearch};-use terminal::{Event as TerminalEvent, terminal_settings::TerminalSettings};-use terminal_view::{TerminalView, terminal_panel::TerminalPanel};+use terminal::Event as TerminalEvent;+#[cfg(any(test, feature = "test-support"))]+use terminal::terminal_settings::TerminalSettings;+use terminal_view::TerminalView;use text::OffsetRangeExt;use theme_settings::ThemeSettings;use ui::{@@ -642,48 +643,6 @@ pub fn init(cx: &mut App) {).register_action(|workspace: &mut Workspace, _: &AddSelectionToThread, window, cx| {- let active_editor = workspace- .active_item(cx)- .and_then(|item| item.act_as::<Editor>(cx));- let has_editor_selection = active_editor.is_some_and(|editor| {- editor.update(cx, |editor, cx| {- editor.has_non_empty_selection(&editor.display_snapshot(cx))- })- });-- let has_terminal_selection = workspace- .active_item(cx)- .and_then(|item| item.act_as::<TerminalView>(cx))- .is_some_and(|terminal_view| {- terminal_view- .read(cx)- .terminal()- .read(cx)- .last_content- .selection_text- .as_ref()- .is_some_and(|text| !text.is_empty())- });-- let has_terminal_panel_selection =- workspace.panel::<TerminalPanel>(cx).is_some_and(|panel| {- let position = match TerminalSettings::get_global(cx).dock {- TerminalDockPosition::Left => DockPosition::Left,- TerminalDockPosition::Bottom => DockPosition::Bottom,- TerminalDockPosition::Right => DockPosition::Right,- };- let dock_is_open =- workspace.dock_at_position(position).read(cx).is_open();- dock_is_open && !panel.read(cx).terminal_selections(cx).is_empty()- });-- if !has_editor_selection- && !has_terminal_selection- && !has_terminal_panel_selection- {- return;- }-let Some(agent_panel) = workspace.panel::<AgentPanel>(cx) else {return;};@@ -9425,18 +9384,16 @@ mod tests {terminal.take_input_log();});- // With only a cursor and nothing highlighted, the action is a no-op and- // must not paste anything into the terminal.workspace.update_in(&mut cx, |_, window, cx| {window.dispatch_action(AddSelectionToThread.boxed_clone(), cx);});cx.run_until_parked();- let pasted_without_selection =- terminal.update(&mut cx, |terminal, _| terminal.take_input_log());- assert!(- pasted_without_selection.is_empty(),- "no selection should paste nothing, got {pasted_without_selection:?}"- );+ let pasted_current_line: String = terminal+ .update(&mut cx, |terminal, _| terminal.take_input_log())+ .into_iter()+ .map(|bytes| String::from_utf8(bytes).expect("pasted bytes should be valid UTF-8"))+ .collect();+ assert_eq!(pasted_current_line, "file.rs:1 ");// Now highlight a portion of the file: from the start of line 2 into line 3.editor.update_in(&mut cx, |editor, window, cx| {