agent: Improve edit file tool card (#29448)

⚠️ Work in progress until all of the to-dos are knocked out:

- [x] Disable soft-wrapping
- [x] Make it foldable only after a certain number of lines
- [x] Display tool status errors
- [x] Fix horizontal scroll now that we've disabled soft-wrap
- [ ] Don't render unnecessary extra lines (will be added later, on a
follow-up PR)

Release Notes:

- N/A

---------

Co-authored-by: Agus Zubiaga <hi@aguz.me>
Co-authored-by: Michael Sloan <mgsloan@gmail.com>
This commit is contained in:
Danilo Leal
2025-04-30 11:21:29 -03:00
committed by GitHub
co-authored by Agus Zubiaga Michael Sloan
parent fbb0fe40ec
commit 128b7d2245
4 changed files with 134 additions and 62 deletions
-7
View File
@@ -871,7 +871,6 @@ pub struct Editor {
show_breadcrumbs: bool,
show_gutter: bool,
show_scrollbars: bool,
disable_scrolling: bool,
disable_expand_excerpt_buttons: bool,
show_line_numbers: Option<bool>,
use_relative_line_numbers: Option<bool>,
@@ -1668,7 +1667,6 @@ impl Editor {
blink_manager: blink_manager.clone(),
show_local_selections: true,
show_scrollbars: true,
disable_scrolling: false,
mode,
show_breadcrumbs: EditorSettings::get_global(cx).toolbar.breadcrumbs,
show_gutter: mode.is_full(),
@@ -16487,11 +16485,6 @@ impl Editor {
cx.notify();
}
pub fn disable_scrolling(&mut self, cx: &mut Context<Self>) {
self.disable_scrolling = true;
cx.notify();
}
pub fn set_show_line_numbers(&mut self, show_line_numbers: bool, cx: &mut Context<Self>) {
self.show_line_numbers = Some(show_line_numbers);
cx.notify();
+1 -3
View File
@@ -5678,9 +5678,7 @@ impl EditorElement {
}
fn paint_mouse_listeners(&mut self, layout: &EditorLayout, window: &mut Window, cx: &mut App) {
if !self.editor.read(cx).disable_scrolling {
self.paint_scroll_wheel_listener(layout, window, cx);
}
self.paint_scroll_wheel_listener(layout, window, cx);
window.on_mouse_event({
let position_map = layout.position_map.clone();
+25 -12
View File
@@ -184,9 +184,6 @@ impl ScrollManager {
window: &mut Window,
cx: &mut Context<Editor>,
) {
if self.forbid_vertical_scroll {
return;
}
let (new_anchor, top_row) = if scroll_position.y <= 0. {
(
ScrollAnchor {
@@ -258,10 +255,16 @@ impl ScrollManager {
window: &mut Window,
cx: &mut Context<Editor>,
) {
if self.forbid_vertical_scroll {
return;
}
self.anchor = anchor;
let adjusted_anchor = if self.forbid_vertical_scroll {
ScrollAnchor {
offset: gpui::Point::new(anchor.offset.x, self.anchor.offset.y),
anchor: self.anchor.anchor,
}
} else {
anchor
};
self.anchor = adjusted_anchor;
cx.emit(EditorEvent::ScrollPositionChanged { local, autoscroll });
self.show_scrollbars(window, cx);
self.autoscroll_request.take();
@@ -404,11 +407,12 @@ impl Editor {
window: &mut Window,
cx: &mut Context<Self>,
) {
let mut delta = scroll_delta;
if self.scroll_manager.forbid_vertical_scroll {
return;
delta.y = 0.0;
}
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
let position = self.scroll_manager.anchor.scroll_position(&display_map) + scroll_delta;
let position = self.scroll_manager.anchor.scroll_position(&display_map) + delta;
self.set_scroll_position_taking_display_map(position, true, false, display_map, window, cx);
}
@@ -418,10 +422,12 @@ impl Editor {
window: &mut Window,
cx: &mut Context<Self>,
) {
let mut position = scroll_position;
if self.scroll_manager.forbid_vertical_scroll {
return;
let current_position = self.scroll_position(cx);
position.y = current_position.y;
}
self.set_scroll_position_internal(scroll_position, true, false, window, cx);
self.set_scroll_position_internal(position, true, false, window, cx);
}
/// Scrolls so that `row` is at the top of the editor view.
@@ -480,8 +486,15 @@ impl Editor {
self.edit_prediction_preview
.set_previous_scroll_position(None);
let adjusted_position = if self.scroll_manager.forbid_vertical_scroll {
let current_position = self.scroll_manager.anchor.scroll_position(&display_map);
gpui::Point::new(scroll_position.x, current_position.y)
} else {
scroll_position
};
self.scroll_manager.set_scroll_position(
scroll_position,
adjusted_position,
&display_map,
local,
autoscroll,