Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix sticky header scroll offset (#45377)
Julia Ryan361b8e0ba9b1
diff --git a/crates/editor/src/scroll/autoscroll.rs b/crates/editor/src/scroll/autoscroll.rsindex 28fd9442193..fc2ecb92051 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;+use multi_buffer::{Anchor, ToPoint};use std::cmp;#[derive(Debug, PartialEq, Eq, Clone, Copy)]@@ -186,6 +186,19 @@ 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 margin = if matches!(self.mode, EditorMode::AutoHeight { .. }) {0.} else {@@ -218,7 +231,7 @@ impl Editor {let was_autoscrolled = match strategy {AutoscrollStrategy::Fit | AutoscrollStrategy::Newest => {let margin = margin.min(self.scroll_manager.vertical_scroll_margin);- let target_top = (target_top - margin).max(0.0);+ let target_top = (target_top - margin - visible_sticky_headers as f64).max(0.0);let target_bottom = target_bottom + margin;let start_row = scroll_position.y;let end_row = start_row + visible_lines;