Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

editor: When expanding first excerpt up, scroll it into view (#41445)

Lukas Wirth6fa823417feb
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index 77fadacfb12..f542b864bb8 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);
}
}