Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Revert "outline: Refactor outline render_item to reuse existing TextStyle (#49166)" (#50258)
Kirill Bulatov703bc3698840
diff --git a/crates/outline/src/outline.rs b/crates/outline/src/outline.rsindex d66036a31d8..454f6f0b578 100644--- a/crates/outline/src/outline.rs+++ b/crates/outline/src/outline.rs@@ -10,7 +10,8 @@ use editor::{MultiBufferOffset, RowHighlightOptions, SelectionEffects};use fuzzy::StringMatch;use gpui::{App, Context, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, HighlightStyle,- ParentElement, Point, Render, Styled, StyledText, Task, WeakEntity, Window, div, rems,+ ParentElement, Point, Render, Styled, StyledText, Task, TextStyle, WeakEntity, Window, div,+ rems,};use language::{Outline, OutlineItem};use ordered_float::OrderedFloat;@@ -406,7 +407,7 @@ pub fn render_item<T>(outline_item: &OutlineItem<T>,match_ranges: impl IntoIterator<Item = Range<usize>>,cx: &App,-) -> impl IntoElement {+) -> StyledText {let highlight_style = HighlightStyle {background_color: Some(cx.theme().colors().text_accent.alpha(0.3)),..Default::default()@@ -414,19 +415,28 @@ pub fn render_item<T>(let custom_highlights = match_ranges.into_iter().map(|range| (range, highlight_style));++ let settings = ThemeSettings::get_global(cx);++ // TODO: We probably shouldn't need to build a whole new text style here+ // but I'm not sure how to get the current one and modify it.+ // Before this change TextStyle::default() was used here, which was giving us the wrong font and text color.+ let text_style = TextStyle {+ color: cx.theme().colors().text,+ font_family: settings.buffer_font.family.clone(),+ font_features: settings.buffer_font.features.clone(),+ font_fallbacks: settings.buffer_font.fallbacks.clone(),+ font_size: settings.buffer_font_size(cx).into(),+ font_weight: settings.buffer_font.weight,+ line_height: relative(1.),+ ..Default::default()+ };let highlights = gpui::combine_highlights(custom_highlights,outline_item.highlight_ranges.iter().cloned(),);- let settings = ThemeSettings::get_global(cx);-- div()- .text_color(cx.theme().colors().text)- .font(settings.buffer_font.clone())- .text_size(settings.buffer_font_size(cx))- .line_height(relative(1.))- .child(StyledText::new(outline_item.text.clone()).with_highlights(highlights))+ StyledText::new(outline_item.text.clone()).with_default_highlights(&text_style, highlights)}#[cfg(test)]diff --git a/crates/outline_panel/src/outline_panel.rs b/crates/outline_panel/src/outline_panel.rsindex 91b0f2e6d45..445f63fa1cd 100644--- a/crates/outline_panel/src/outline_panel.rs+++ b/crates/outline_panel/src/outline_panel.rs@@ -2618,21 +2618,24 @@ impl OutlinePanel {} else {&search_matches};- let outline_item = OutlineItem {- depth,- annotation_range: None,- range: search_data.context_range.clone(),- text: search_data.context_text.clone(),- source_range_for_text: search_data.context_range.clone(),- highlight_ranges: search_data- .highlights_data- .get()- .cloned()- .unwrap_or_default(),- name_ranges: search_data.search_match_indices.clone(),- body_range: Some(search_data.context_range.clone()),- };- let label_element = outline::render_item(&outline_item, match_ranges.iter().cloned(), cx);+ let label_element = outline::render_item(+ &OutlineItem {+ depth,+ annotation_range: None,+ range: search_data.context_range.clone(),+ text: search_data.context_text.clone(),+ source_range_for_text: search_data.context_range.clone(),+ highlight_ranges: search_data+ .highlights_data+ .get()+ .cloned()+ .unwrap_or_default(),+ name_ranges: search_data.search_match_indices.clone(),+ body_range: Some(search_data.context_range.clone()),+ },+ match_ranges.iter().cloned(),+ cx,+ );let truncated_contents_label = || Label::new(TRUNCATED_CONTEXT_MARK);let entire_label = h_flex().justify_center()