agent: Do not render unnecessary lines in edit file tool card (#29766)

This PR prevents any unnecessary lines from being rendered in the edit
file tool card in the case of small diffs.

I think this (hopefully) addresses the last remaining task from
https://github.com/zed-industries/zed/pull/29448.

| `main` | This PR |
| --- | --- |
| <img width="634" alt="main"
src="https://github.com/user-attachments/assets/7c06394e-957a-4d36-a484-5974687041e9"
/> | <img width="634" alt="PR"
src="https://github.com/user-attachments/assets/84206d5a-a93a-4a42-99ca-7cdebb0d91bb"
/> |

(The last empty line in the second image is an empty line present in the
file itself)

---

n the second commit I also preemtively disabled vertical overscrolling
for full mode editors which are sized by content. This is basically the
same fix as in https://github.com/zed-industries/zed/pull/28471.
Strictly speaking, this is not needed for the fix here, but I thought it
might be nice to have for the future to prevent any issues from occuring
due to overscroll.

Release Notes:

- agent: Improved rendering of small diffs for the edit file tool card.
This commit is contained in:
Finn Evers 2025-05-02 01:40:12 +02:00 committed by GitHub
parent 758d260cec
commit 92b9ecd7d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 8 deletions

View file

@ -577,13 +577,10 @@ impl ToolCard for EditFileToolCard {
card.child( card.child(
v_flex() v_flex()
.relative() .relative()
.map(|editor_container| { .h_full()
if self.full_height_expanded { .when(!self.full_height_expanded, |editor_container| {
editor_container.h_full() editor_container
} else { .max_h(DEFAULT_COLLAPSED_LINES as f32 * editor_line_height)
editor_container
.h(DEFAULT_COLLAPSED_LINES as f32 * editor_line_height)
}
}) })
.overflow_hidden() .overflow_hidden()
.border_t_1() .border_t_1()

View file

@ -6874,7 +6874,12 @@ impl Element for EditorElement {
// The max scroll position for the top of the window // The max scroll position for the top of the window
let max_scroll_top = if matches!( let max_scroll_top = if matches!(
snapshot.mode, snapshot.mode,
EditorMode::AutoHeight { .. } | EditorMode::SingleLine { .. } EditorMode::SingleLine { .. }
| EditorMode::AutoHeight { .. }
| EditorMode::Full {
sized_by_content: true,
..
}
) { ) {
(max_row - height_in_lines + 1.).max(0.) (max_row - height_in_lines + 1.).max(0.)
} else { } else {