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
parent fbb0fe40ec
commit 128b7d2245
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 134 additions and 62 deletions

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,