Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
editor: Fix sticky scroll showing decorator line instead of declaration (#53288)
Valery Borovsky9affe8cbace5
diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rsindex 6dfbf334024..7bc8eac0bfc 100644--- a/crates/editor/src/editor_tests.rs+++ b/crates/editor/src/editor_tests.rs@@ -32715,6 +32715,78 @@ async fn test_sticky_scroll(cx: &mut TestAppContext) {assert_eq!(sticky_headers(10.0), vec![]);}+#[gpui::test]+async fn test_sticky_scroll_with_decoration_prefix_in_item(cx: &mut TestAppContext) {+ init_test(cx, |_| {});+ let mut cx = EditorTestContext::new(cx).await;++ let language = Arc::new(+ Language::new(+ LanguageConfig {+ name: "TypeScript".into(),+ ..Default::default()+ },+ Some(tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into()),+ )+ .with_outline_query(+ r#"+ (class_declaration+ "class" @context+ name: (_) @name) @item+ "#,+ )+ .expect("TypeScript outline query"),+ );++ let buffer = indoc! {"+ ˇ@Decorator+ class Foo {+ x = 1;+ y = 2;+ z = 3;+ w = 4;+ }+ "};+ cx.set_state(buffer);+ cx.update_editor(|e, _, cx| {+ e.buffer()+ .read(cx)+ .as_singleton()+ .unwrap()+ .update(cx, |buffer, cx| {+ buffer.set_language(Some(language), cx);+ })+ });++ let mut sticky_headers = |offset: ScrollOffset| {+ cx.update_editor(|e, window, cx| {+ e.scroll(gpui::Point { x: 0., y: offset }, None, window, cx);+ });+ cx.run_until_parked();+ cx.update_editor(|e, window, cx| {+ EditorElement::sticky_headers(&e, &e.snapshot(window, cx))+ .into_iter()+ .map(+ |StickyHeader {+ start_point,+ offset,+ ..+ }| { (start_point, offset) },+ )+ .collect::<Vec<_>>()+ })+ };++ let class_foo = Point { row: 1, column: 0 };++ assert_eq!(sticky_headers(0.0), vec![]);+ assert_eq!(sticky_headers(1.5), vec![(class_foo, 0.0)]);+ assert_eq!(sticky_headers(2.5), vec![(class_foo, 0.0)]);+ assert_eq!(sticky_headers(5.5), vec![(class_foo, -0.5)]);+ assert_eq!(sticky_headers(6.0), vec![]);+ assert_eq!(sticky_headers(7.0), vec![]);+}+#[gpui::test]async fn test_sticky_scroll_with_expanded_deleted_diff_hunks(executor: BackgroundExecutor,diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex 0646bf7a068..e76e1cd2486 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -4728,7 +4728,10 @@ impl EditorElement {let mut rows = Vec::<StickyHeader>::new();for item in editor.sticky_headers.iter().flatten() {- let start_point = item.range.start.to_point(snapshot.buffer_snapshot());+ let start_point = item+ .source_range_for_text+ .start+ .to_point(snapshot.buffer_snapshot());let end_point = item.range.end.to_point(snapshot.buffer_snapshot());let sticky_row = snapshot