From 703bc3698840a67a3984e4a80eefdaac6ce29dc1 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 27 Feb 2026 00:27:24 +0100 Subject: [PATCH] Revert "outline: Refactor outline render_item to reuse existing TextStyle (#49166)" (#50258) This reverts commit 69e5ff7c76faa888ac71ff1d83cd335fb183b065. Release Notes: - N/A --- crates/outline/src/outline.rs | 30 ++++++++++++++------- crates/outline_panel/src/outline_panel.rs | 33 ++++++++++++----------- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/crates/outline/src/outline.rs b/crates/outline/src/outline.rs index d66036a31d8a931a652a8ec0ca9019e5cdcaa7b9..454f6f0b578ce25785f0a356251c8af64776772f 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( outline_item: &OutlineItem, match_ranges: impl IntoIterator>, 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( 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.rs index 91b0f2e6d45d87170c5bb8ecda47df3e1a64626e..445f63fa1cdc38cb358cf033cc49f404aa6e6d94 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()