Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
editor: Use `highlight_text` to highlight matching brackets, fix unnecessary inlay hint highlighting (#36540)
Sachith Shetty68f97d6069ad
diff --git a/crates/editor/src/highlight_matching_bracket.rs b/crates/editor/src/highlight_matching_bracket.rsindex e38197283d4..aa4e616924a 100644--- a/crates/editor/src/highlight_matching_bracket.rs+++ b/crates/editor/src/highlight_matching_bracket.rs@@ -1,6 +1,7 @@use crate::{Editor, RangeToAnchorExt};-use gpui::{Context, Window};+use gpui::{Context, HighlightStyle, Window};use language::CursorShape;+use theme::ActiveTheme;enum MatchingBracketHighlight {}@@ -9,7 +10,7 @@ pub fn refresh_matching_bracket_highlights(window: &mut Window,cx: &mut Context<Editor>,) {- editor.clear_background_highlights::<MatchingBracketHighlight>(cx);+ editor.clear_highlights::<MatchingBracketHighlight>(cx);let newest_selection = editor.selections.newest::<usize>(cx);// Don't highlight brackets if the selection isn't empty@@ -35,12 +36,19 @@ pub fn refresh_matching_bracket_highlights(.buffer_snapshot.innermost_enclosing_bracket_ranges(head..tail, None){- editor.highlight_background::<MatchingBracketHighlight>(- &[+ editor.highlight_text::<MatchingBracketHighlight>(+ vec![opening_range.to_anchors(&snapshot.buffer_snapshot),closing_range.to_anchors(&snapshot.buffer_snapshot),],- |theme| theme.colors().editor_document_highlight_bracket_background,+ HighlightStyle {+ background_color: Some(+ cx.theme()+ .colors()+ .editor_document_highlight_bracket_background,+ ),+ ..Default::default()+ },cx,)}@@ -104,7 +112,7 @@ mod tests {another_test(1, 2, 3);}"#});- cx.assert_editor_background_highlights::<MatchingBracketHighlight>(indoc! {r#"+ cx.assert_editor_text_highlights::<MatchingBracketHighlight>(indoc! {r#"pub fn test«(»"Test argument"«)» {another_test(1, 2, 3);}@@ -115,7 +123,7 @@ mod tests {another_test(1, ˇ2, 3);}"#});- cx.assert_editor_background_highlights::<MatchingBracketHighlight>(indoc! {r#"+ cx.assert_editor_text_highlights::<MatchingBracketHighlight>(indoc! {r#"pub fn test("Test argument") {another_test«(»1, 2, 3«)»;}@@ -126,7 +134,7 @@ mod tests {anotherˇ_test(1, 2, 3);}"#});- cx.assert_editor_background_highlights::<MatchingBracketHighlight>(indoc! {r#"+ cx.assert_editor_text_highlights::<MatchingBracketHighlight>(indoc! {r#"pub fn test("Test argument") «{»another_test(1, 2, 3);«}»@@ -138,7 +146,7 @@ mod tests {another_test(1, 2, 3);}"#});- cx.assert_editor_background_highlights::<MatchingBracketHighlight>(indoc! {r#"+ cx.assert_editor_text_highlights::<MatchingBracketHighlight>(indoc! {r#"pub fn test("Test argument") {another_test(1, 2, 3);}@@ -150,8 +158,8 @@ mod tests {another_test(1, 2, 3);}"#});- cx.assert_editor_background_highlights::<MatchingBracketHighlight>(indoc! {r#"- pub fn test("Test argument") {+ cx.assert_editor_text_highlights::<MatchingBracketHighlight>(indoc! {r#"+ pub fn test«("Test argument") {another_test(1, 2, 3);}"#});