agent: Improve terminal tool card design (#29712)

To-dos:

- [x] Expose the command to defend against cases where that's just super
long
- [x] Tackle the vertical scroll conflict with panel scroll
- [x] Reduce default font-size

Release Notes:

- N/A

---------

Co-authored-by: Ben Brandt <benjamin.j.brandt@gmail.com>
Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com>
Co-authored-by: Agus Zubiaga <hi@aguz.me>
This commit is contained in:
Danilo Leal 2025-05-05 15:50:53 -03:00 committed by GitHub
parent e64f5ff358
commit 7dfbe0b908
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 174 additions and 145 deletions

View file

@ -1,9 +1,9 @@
use editor::{CursorLayout, HighlightedRange, HighlightedRangeLine};
use gpui::{
AnyElement, App, AvailableSpace, Bounds, ContentMask, Context, DispatchPhase, Element,
ElementId, Entity, FocusHandle, Font, FontStyle, FontWeight, GlobalElementId, HighlightStyle,
Hitbox, Hsla, InputHandler, InteractiveElement, Interactivity, IntoElement, LayoutId,
ModifiersChangedEvent, MouseButton, MouseMoveEvent, Pixels, Point, ShapedLine,
ElementId, Entity, FocusHandle, Focusable, Font, FontStyle, FontWeight, GlobalElementId,
HighlightStyle, Hitbox, Hsla, InputHandler, InteractiveElement, Interactivity, IntoElement,
LayoutId, ModifiersChangedEvent, MouseButton, MouseMoveEvent, Pixels, Point, ShapedLine,
StatefulInteractiveElement, StrikethroughStyle, Styled, TextRun, TextStyle, UTF16Selection,
UnderlineStyle, WeakEntity, WhiteSpace, Window, WindowTextSystem, div, fill, point, px,
relative, size,
@ -158,6 +158,7 @@ pub struct TerminalElement {
focused: bool,
cursor_visible: bool,
interactivity: Interactivity,
embedded: bool,
block_below_cursor: Option<Rc<BlockProperties>>,
}
@ -178,6 +179,7 @@ impl TerminalElement {
focused: bool,
cursor_visible: bool,
block_below_cursor: Option<Rc<BlockProperties>>,
embedded: bool,
) -> TerminalElement {
TerminalElement {
terminal,
@ -187,6 +189,7 @@ impl TerminalElement {
focus: focus.clone(),
cursor_visible,
block_below_cursor,
embedded,
interactivity: Default::default(),
}
.track_focus(&focus)
@ -503,11 +506,15 @@ impl TerminalElement {
);
self.interactivity.on_scroll_wheel({
let terminal_view = self.terminal_view.downgrade();
move |e, _, cx| {
move |e, window, cx| {
terminal_view
.update(cx, |terminal_view, cx| {
terminal_view.scroll_wheel(e, cx);
cx.notify();
if !terminal_view.embedded
|| terminal_view.focus_handle(cx).is_focused(window)
{
terminal_view.scroll_wheel(e, cx);
cx.notify();
}
})
.ok();
}
@ -580,6 +587,16 @@ impl Element for TerminalElement {
window: &mut Window,
cx: &mut App,
) -> (LayoutId, Self::RequestLayoutState) {
if self.embedded {
let scrollable = {
let term = self.terminal.read(cx);
!term.scrolled_to_top() && !term.scrolled_to_bottom() && self.focused
};
if scrollable {
self.interactivity.occlude_mouse();
}
}
let layout_id =
self.interactivity
.request_layout(global_id, window, cx, |mut style, window, cx| {
@ -636,10 +653,14 @@ impl Element for TerminalElement {
let font_weight = terminal_settings.font_weight.unwrap_or_default();
let line_height = terminal_settings.line_height.value();
let font_size = terminal_settings.font_size;
let font_size =
font_size.map_or(buffer_font_size, |size| theme::adjusted_font_size(size, cx));
let font_size = if self.embedded {
window.text_style().font_size.to_pixels(window.rem_size())
} else {
terminal_settings
.font_size
.map_or(buffer_font_size, |size| theme::adjusted_font_size(size, cx))
};
let theme = cx.theme().clone();