From 92b9ecd7d297b3ded8ca9e645312a414ca32173b Mon Sep 17 00:00:00 2001 From: Finn Evers Date: Fri, 2 May 2025 01:40:12 +0200 Subject: [PATCH] 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 | | --- | --- | | main | PR | (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. --- crates/assistant_tools/src/edit_file_tool.rs | 11 ++++------- crates/editor/src/element.rs | 7 ++++++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/assistant_tools/src/edit_file_tool.rs b/crates/assistant_tools/src/edit_file_tool.rs index 0c995a58fc0da8f74b871acae257826497d80429..be276fcc816371738f22d1e9b6c22cfa5da79968 100644 --- a/crates/assistant_tools/src/edit_file_tool.rs +++ b/crates/assistant_tools/src/edit_file_tool.rs @@ -577,13 +577,10 @@ impl ToolCard for EditFileToolCard { card.child( v_flex() .relative() - .map(|editor_container| { - if self.full_height_expanded { - editor_container.h_full() - } else { - editor_container - .h(DEFAULT_COLLAPSED_LINES as f32 * editor_line_height) - } + .h_full() + .when(!self.full_height_expanded, |editor_container| { + editor_container + .max_h(DEFAULT_COLLAPSED_LINES as f32 * editor_line_height) }) .overflow_hidden() .border_t_1() diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 56bb7740fa84eaa371c6cd45381f280acd013729..7c8848d841ea08b33b22b9802dbb07786c80f58f 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -6874,7 +6874,12 @@ impl Element for EditorElement { // The max scroll position for the top of the window let max_scroll_top = if matches!( snapshot.mode, - EditorMode::AutoHeight { .. } | EditorMode::SingleLine { .. } + EditorMode::SingleLine { .. } + | EditorMode::AutoHeight { .. } + | EditorMode::Full { + sized_by_content: true, + .. + } ) { (max_row - height_in_lines + 1.).max(0.) } else {