Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
agent_ui: Fix terminal overflow in agent terminal output (#64328)
Chris Drackettf8adffe9d145
diff --git a/crates/agent_ui/src/entry_view_state.rs b/crates/agent_ui/src/entry_view_state.rsindex 4532d4ec18e..63a374ad1aa 100644--- a/crates/agent_ui/src/entry_view_state.rs+++ b/crates/agent_ui/src/entry_view_state.rs@@ -10,8 +10,8 @@ use editor::{SizingBehavior,};use gpui::{- AnyEntity, App, AppContext as _, Entity, EntityId, EventEmitter, FocusHandle, Focusable,- ScrollHandle, TextStyleRefinement, WeakEntity, Window,+ AnyEntity, App, AppContext as _, Corners, Entity, EntityId, EventEmitter, FocusHandle,+ Focusable, ScrollHandle, TextStyleRefinement, WeakEntity, Window,};use language::language_settings::SoftWrap;use project::{AgentId, Project, project_settings::DiagnosticSeverity};@@ -643,6 +643,22 @@ fn create_terminal(cx,).with_read_only(read_only);++ // GPUI can't clip children to rounded corners, so the terminal has to+ // round its own background to avoid painting over the corners of the+ // tool card it sits in.+ // This matches the `rounded_md`/`rounded_b_md` on that card, which GPUI+ // doesn't expose as a value, so if the card's corner radii ever change,+ // this also needs to be updated.+ view.set_background_corner_radii(+ Some(Corners {+ bottom_left: gpui::rems(0.375),+ bottom_right: gpui::rems(0.375),+ ..Default::default()+ }),+ cx,+ );+view.set_embedded_mode(Some(1000), cx);view})diff --git a/crates/terminal_view/src/terminal_element.rs b/crates/terminal_view/src/terminal_element.rsindex 7e5c2ab2cda..1af9d06eaeb 100644--- a/crates/terminal_view/src/terminal_element.rs+++ b/crates/terminal_view/src/terminal_element.rs@@ -1585,8 +1585,14 @@ impl Element for TerminalElement {let terminal_view = self.terminal_view.read(cx);let scroll_top = terminal_view.scroll_top;let mouse_input_mode = terminal_view.mouse_input_mode();+ let corner_radii = terminal_view+ .background_corner_radii+ .unwrap_or_default()+ .map(|radius| radius.to_pixels(window.rem_size()))+ .clamp_radii_for_quad_size(bounds.size);++ window.paint_quad(fill(bounds, layout.background_color).corner_radii(corner_radii));- window.paint_quad(fill(bounds, layout.background_color));let origin = layout.dimensions.bounds.origin - GpuiPoint::new(px(0.), scroll_top);let scale_factor = window.scale_factor();let snap_px = |value: Pixels| {diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rsindex 76510345471..ac054702d46 100644--- a/crates/terminal_view/src/terminal_view.rs+++ b/crates/terminal_view/src/terminal_view.rs@@ -9,10 +9,10 @@ use editor::{ui_scrollbar_settings_from_raw,};use gpui::{- Action, AnyElement, App, ClipboardEntry, DismissEvent, Entity, EventEmitter, ExternalPaths,- FocusHandle, Focusable, Font, KeyContext, KeyDownEvent, Keystroke, MouseButton, MouseDownEvent,- Pixels, Point as GpuiPoint, Render, ScrollWheelEvent, Styled, Subscription, Task, TaskExt,- WeakEntity, actions, anchored, deferred, div,+ Action, AnyElement, App, ClipboardEntry, Corners, DismissEvent, Entity, EventEmitter,+ ExternalPaths, FocusHandle, Focusable, Font, KeyContext, KeyDownEvent, Keystroke, MouseButton,+ MouseDownEvent, Pixels, Point as GpuiPoint, Rems, Render, ScrollWheelEvent, Styled,+ Subscription, Task, TaskExt, WeakEntity, actions, anchored, deferred, div,};use menu;use persistence::TerminalDb;@@ -139,6 +139,13 @@ pub struct TerminalView {cursor_shape: CursorShape,blink_manager: Entity<BlinkManager>,mode: TerminalMode,+ /// Corner radii for the terminal's background, for when it's embedded in a+ /// container with rounded corners.+ ///+ /// GPUI can't clip children to rounded corners, so without this the square+ /// background paints over the container's corners. Only the background is+ /// rounded, terminal content isn't clipped.+ background_corner_radii: Option<Corners<Rems>>,read_only: bool,// Explicit override for whether workspace-specific context menu actions are shown.// When `None`, visibility is derived from `mode` (hidden for embedded terminals).@@ -292,6 +299,7 @@ impl TerminalView {hover: None,hover_tooltip_update: Task::ready(()),mode: TerminalMode::Standalone,+ background_corner_radii: None,read_only: false,show_workspace_actions: None,workspace_id,@@ -322,6 +330,16 @@ impl TerminalView {cx.notify();}+ /// Rounds the background without clipping terminal content to the corners.+ pub fn set_background_corner_radii(+ &mut self,+ corner_radii: Option<Corners<Rems>>,+ cx: &mut Context<Self>,+ ) {+ self.background_corner_radii = corner_radii;+ cx.notify();+ }+pub fn is_read_only(&self) -> bool {self.read_only}@@ -1467,6 +1485,12 @@ impl Render for TerminalView {.id("terminal-view-container").size_full().bg(cx.theme().colors().editor_background)+ .when_some(self.background_corner_radii, |this, radii| {+ this.rounded_tl(radii.top_left)+ .rounded_tr(radii.top_right)+ .rounded_bl(radii.bottom_left)+ .rounded_br(radii.bottom_right)+ }).child(TerminalElement::new(terminal_handle,terminal_view_handle,