diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index d1e817ccf950a34fd6ed2503a609dcab61d57f22..764ba887bc25898456ca2f1b3656096c58d2ac4b 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -10164,6 +10164,11 @@ impl Element for EditorElement { } else { None }; + self.editor.update(cx, |editor, _| { + editor.scroll_manager.set_sticky_header_line_count( + sticky_headers.as_ref().map_or(0, |h| h.lines.len()), + ); + }); let indent_guides = self.layout_indent_guides( content_origin, text_hitbox.origin, diff --git a/crates/editor/src/scroll.rs b/crates/editor/src/scroll.rs index 422be9a54e7cfcc40484e4093eeab6c94ce7d8ee..4c8bdcf16d8abdfac473f4200248a6bcdbd785e8 100644 --- a/crates/editor/src/scroll.rs +++ b/crates/editor/src/scroll.rs @@ -152,6 +152,8 @@ pub struct ScrollManager { pub(crate) vertical_scroll_margin: ScrollOffset, anchor: ScrollAnchor, ongoing: OngoingScroll, + /// Number of sticky header lines currently being rendered for the current scroll position. + sticky_header_line_count: usize, /// The second element indicates whether the autoscroll request is local /// (true) or remote (false). Local requests are initiated by user actions, /// while remote requests come from external sources. @@ -177,6 +179,7 @@ impl ScrollManager { vertical_scroll_margin: EditorSettings::get_global(cx).vertical_scroll_margin, anchor: ScrollAnchor::new(), ongoing: OngoingScroll::new(), + sticky_header_line_count: 0, autoscroll_request: None, show_scrollbars: true, hide_scrollbar_task: None, @@ -192,6 +195,7 @@ impl ScrollManager { pub fn clone_state(&mut self, other: &Self) { self.anchor = other.anchor; self.ongoing = other.ongoing; + self.sticky_header_line_count = other.sticky_header_line_count; } pub fn anchor(&self) -> ScrollAnchor { @@ -211,6 +215,14 @@ impl ScrollManager { self.anchor.scroll_position(snapshot) } + pub fn sticky_header_line_count(&self) -> usize { + self.sticky_header_line_count + } + + pub fn set_sticky_header_line_count(&mut self, count: usize) { + self.sticky_header_line_count = count; + } + fn set_scroll_position( &mut self, scroll_position: gpui::Point, diff --git a/crates/editor/src/scroll/autoscroll.rs b/crates/editor/src/scroll/autoscroll.rs index 068acffcad15b0217439efe767518c8cdbc6bb04..2078cf45e8179806541883c5dbf19982b2b5318f 100644 --- a/crates/editor/src/scroll/autoscroll.rs +++ b/crates/editor/src/scroll/autoscroll.rs @@ -5,7 +5,7 @@ use crate::{ }; use gpui::{Bounds, Context, Pixels, Window}; use language::Point; -use multi_buffer::{Anchor, ToPoint}; +use multi_buffer::Anchor; use std::cmp; #[derive(Debug, PartialEq, Eq, Clone, Copy)] @@ -186,18 +186,7 @@ impl Editor { } } - let style = self.style(cx).clone(); - let sticky_headers = self.sticky_headers(&style, cx).unwrap_or_default(); - let visible_sticky_headers = sticky_headers - .iter() - .filter(|h| { - let buffer_snapshot = display_map.buffer_snapshot(); - let buffer_range = - h.range.start.to_point(buffer_snapshot)..h.range.end.to_point(buffer_snapshot); - - buffer_range.contains(&Point::new(target_top as u32, 0)) - }) - .count(); + let visible_sticky_headers = self.scroll_manager.sticky_header_line_count(); let margin = if matches!(self.mode, EditorMode::AutoHeight { .. }) { 0.