Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
editor: Fix excerpt down scroll behavior to only scroll when there are enough lines (#28231)
Smit Barmase99a9647b78e8
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 4f73b3e2d61..1d64ea5a44c 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -183,7 +183,7 @@ use std::{};pub use sum_tree::Bias;use sum_tree::TreeMap;-use text::{BufferId, OffsetUtf16, Rope};+use text::{BufferId, FromAnchor, OffsetUtf16, Rope};use theme::{ActiveTheme, PlayerColor, StatusColors, SyntaxTheme, ThemeColors, ThemeSettings,observe_buffer_font_size_adjustment,@@ -12718,12 +12718,33 @@ impl Editor {cx: &mut Context<Self>,) {let current_scroll_position = self.scroll_position(cx);- let lines = EditorSettings::get_global(cx).expand_excerpt_lines;+ let lines_to_expand = EditorSettings::get_global(cx).expand_excerpt_lines;+ let mut should_scroll_up = false;++ if direction == ExpandExcerptDirection::Down {+ let multi_buffer = self.buffer.read(cx);+ let snapshot = multi_buffer.snapshot(cx);+ if let Some(buffer_id) = snapshot.buffer_id_for_excerpt(excerpt) {+ if let Some(buffer) = multi_buffer.buffer(buffer_id) {+ if let Some(excerpt_range) = snapshot.buffer_range_for_excerpt(excerpt) {+ let buffer_snapshot = buffer.read(cx).snapshot();+ 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;+ }+ }+ }+ }+self.buffer.update(cx, |buffer, cx| {- buffer.expand_excerpts([excerpt], lines, direction, cx)+ buffer.expand_excerpts([excerpt], lines_to_expand, direction, cx)});- if direction == ExpandExcerptDirection::Down {- let new_scroll_position = current_scroll_position + gpui::Point::new(0.0, lines as f32);++ if should_scroll_up {+ let new_scroll_position =+ current_scroll_position + gpui::Point::new(0.0, lines_to_expand as f32);self.set_scroll_position(new_scroll_position, window, cx);}}