From 6fa823417feb7909adaa648fd6822d9adde2c47f Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 29 Oct 2025 11:32:42 +0100 Subject: [PATCH] editor: When expanding first excerpt up, scroll it into view (#41445) Before https://github.com/user-attachments/assets/2390e924-112a-43fa-8ab8-429a55456d12 After https://github.com/user-attachments/assets/b47c95f0-ccd9-40a6-ab04-28295158102e Release Notes: - Fixed an issue where expanding the first excerpt upwards would expand it out of view --- crates/editor/src/editor.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 77fadacfb12f08732d63f652164dd709724dc59b..f542b864bb8de977bc0890bf9fb313dfcdf7fbd5 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -15845,7 +15845,7 @@ impl Editor { ) { let current_scroll_position = self.scroll_position(cx); let lines_to_expand = EditorSettings::get_global(cx).expand_excerpt_lines; - let mut should_scroll_up = false; + let mut scroll = None; if direction == ExpandExcerptDirection::Down { let multi_buffer = self.buffer.read(cx); @@ -15858,17 +15858,30 @@ impl Editor { let excerpt_end_row = Point::from_anchor(&excerpt_range.end, &buffer_snapshot).row; let last_row = buffer_snapshot.max_point().row; let lines_below = last_row.saturating_sub(excerpt_end_row); - should_scroll_up = lines_below >= lines_to_expand; + if lines_below >= lines_to_expand { + scroll = Some( + current_scroll_position + + gpui::Point::new(0.0, lines_to_expand as ScrollOffset), + ); + } } } + if direction == ExpandExcerptDirection::Up + && self + .buffer + .read(cx) + .snapshot(cx) + .excerpt_before(excerpt) + .is_none() + { + scroll = Some(current_scroll_position); + } self.buffer.update(cx, |buffer, cx| { buffer.expand_excerpts([excerpt], lines_to_expand, direction, cx) }); - if should_scroll_up { - let new_scroll_position = - current_scroll_position + gpui::Point::new(0.0, lines_to_expand as ScrollOffset); + if let Some(new_scroll_position) = scroll { self.set_scroll_position(new_scroll_position, window, cx); } }