From 2230f3b09d93ec58a10b056a779e6614c739e44c Mon Sep 17 00:00:00 2001 From: Smit Barmase Date: Wed, 19 Mar 2025 19:54:52 +0530 Subject: [PATCH] editor: Preserve expand excerpt down button position (#27058) When you press the "Expand Excerpt Down" button, the editor will scroll up by the same amount to keep the button in same place. This allows you to expand the excerpt rapidly without moving your mouse. Before: https://github.com/user-attachments/assets/376350ac-6f21-4ce0-a383-b2c9ca4f45bb After: https://github.com/user-attachments/assets/4fba4173-5f01-4220-990a-65820ac40cf5 Release Notes: - Improved "Expand Excerpt Down" so the button stays in place, allowing rapid expansion without moving the mouse. --- crates/editor/src/editor.rs | 8 +++++++- crates/editor/src/element.rs | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index fdb443e987..6f247d2768 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -12120,12 +12120,18 @@ impl Editor { &mut self, excerpt: ExcerptId, direction: ExpandExcerptDirection, + window: &mut Window, cx: &mut Context, ) { + let current_scroll_position = self.scroll_position(cx); let lines = EditorSettings::get_global(cx).expand_excerpt_lines; self.buffer.update(cx, |buffer, cx| { buffer.expand_excerpts([excerpt], lines, direction, cx) - }) + }); + if direction == ExpandExcerptDirection::Down { + let new_scroll_position = current_scroll_position + gpui::Point::new(0.0, lines as f32); + self.set_scroll_position(new_scroll_position, window, cx); + } } pub fn go_to_singleton_buffer_point( diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 5001dcebbd..f122aaa9d8 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -2263,9 +2263,9 @@ impl EditorElement { .selected_icon_color(Color::Custom(cx.theme().colors().editor_foreground)) .icon_size(IconSize::Custom(rems(editor_font_size / window.rem_size()))) .width(width.into()) - .on_click(move |_, _, cx| { + .on_click(move |_, window, cx| { editor.update(cx, |editor, cx| { - editor.expand_excerpt(excerpt_id, direction, cx); + editor.expand_excerpt(excerpt_id, direction, window, cx); }); }) .tooltip(Tooltip::for_action_title(