From 56646e6bc32a1c66eb6972edfe59ad65f64af3a7 Mon Sep 17 00:00:00 2001 From: Michael Benfield Date: Fri, 19 Dec 2025 11:37:57 -0800 Subject: [PATCH] Inline assistant: Don't scroll up too high (#45171) In the case of large vertical_scroll_margin, we could scroll up such that the assistant was out of view. Now, keep it no lower than the center of the editor. Closes #18058 Release Notes: - N/A --- crates/agent_ui/src/inline_assistant.rs | 28 ++++++++++++------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/crates/agent_ui/src/inline_assistant.rs b/crates/agent_ui/src/inline_assistant.rs index 671579f9ef018b495b7993279a852595c78d3e02..b3c14c5a0ec332f66c300023759db9f09b94dc6f 100644 --- a/crates/agent_ui/src/inline_assistant.rs +++ b/crates/agent_ui/src/inline_assistant.rs @@ -1259,28 +1259,26 @@ impl InlineAssistant { let bottom = top + 1.0; (top, bottom) }); - let mut scroll_target_top = scroll_target_range.0; - let mut scroll_target_bottom = scroll_target_range.1; - - scroll_target_top -= editor.vertical_scroll_margin() as ScrollOffset; - scroll_target_bottom += editor.vertical_scroll_margin() as ScrollOffset; - let height_in_lines = editor.visible_line_count().unwrap_or(0.); + let vertical_scroll_margin = editor.vertical_scroll_margin() as ScrollOffset; + let scroll_target_top = (scroll_target_range.0 - vertical_scroll_margin) + // Don't scroll up too far in the case of a large vertical_scroll_margin. + .max(scroll_target_range.0 - height_in_lines / 2.0); + let scroll_target_bottom = (scroll_target_range.1 + vertical_scroll_margin) + // Don't scroll down past where the top would still be visible. + .min(scroll_target_top + height_in_lines); + let scroll_top = editor.scroll_position(cx).y; let scroll_bottom = scroll_top + height_in_lines; if scroll_target_top < scroll_top { editor.set_scroll_position(point(0., scroll_target_top), window, cx); } else if scroll_target_bottom > scroll_bottom { - if (scroll_target_bottom - scroll_target_top) <= height_in_lines { - editor.set_scroll_position( - point(0., scroll_target_bottom - height_in_lines), - window, - cx, - ); - } else { - editor.set_scroll_position(point(0., scroll_target_top), window, cx); - } + editor.set_scroll_position( + point(0., scroll_target_bottom - height_in_lines), + window, + cx, + ); } }); }