From 30824089b204cda8e7be209577d4f2780004b885 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:20:36 -0600 Subject: [PATCH] Use buffer font when rendering editor breadcrumbs and diagnostics (cherry-pick #10488) (#10495) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cherry-picked Use buffer font when rendering editor breadcrumbs and diagnostics (#10488) Before: Screenshot 2024-04-12 at 12 00 00 PM After: Screenshot 2024-04-12 at 12 11 37 PM Release Notes: - N/A Co-authored-by: Mikayla Maki --- crates/breadcrumbs/src/breadcrumbs.rs | 7 +++++++ crates/editor/src/editor.rs | 5 +++++ crates/editor/src/items.rs | 7 ++++++- crates/terminal_view/src/terminal_view.rs | 1 + crates/workspace/src/item.rs | 3 ++- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/crates/breadcrumbs/src/breadcrumbs.rs b/crates/breadcrumbs/src/breadcrumbs.rs index 4c8a7cb33f30081f2ddc49fb2ab92d45390dbfe5..89edd3606b0736cae824f2458b5f3c5e55e7362a 100644 --- a/crates/breadcrumbs/src/breadcrumbs.rs +++ b/crates/breadcrumbs/src/breadcrumbs.rs @@ -52,12 +52,19 @@ impl Render for Breadcrumbs { Some(BreadcrumbText { text: "⋯".into(), highlights: None, + font: None, }), ); } let highlighted_segments = segments.into_iter().map(|segment| { let mut text_style = cx.text_style(); + if let Some(font) = segment.font { + text_style.font_family = font.family; + text_style.font_features = font.features; + text_style.font_style = font.style; + text_style.font_weight = font.weight; + } text_style.color = Color::Muted.color(cx); StyledText::new(segment.text.replace('\n', "␤")) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 710e040e96cf7a0966f6dc3f8c16d1b413bb3f21..84a08fcd55413335762500030b8e27be51e461cd 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -10568,6 +10568,11 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, _is_valid: bool) -> Ren let mut text_style = cx.text_style().clone(); text_style.color = diagnostic_style(diagnostic.severity, true, cx.theme().status()); + let theme_settings = ThemeSettings::get_global(cx); + text_style.font_family = theme_settings.buffer_font.family.clone(); + text_style.font_style = theme_settings.buffer_font.style; + text_style.font_features = theme_settings.buffer_font.features; + text_style.font_weight = theme_settings.buffer_font.weight; let multi_line_diagnostic = diagnostic.message.contains('\n'); diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index e3e596a90af986e49c030d140016cc2cfad165be..38a1b64c8303a81c0e58f4d672b930fbb382b020 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -30,7 +30,7 @@ use std::{ sync::Arc, }; use text::{BufferId, Selection}; -use theme::Theme; +use theme::{Theme, ThemeSettings}; use ui::{h_flex, prelude::*, Label}; use util::{paths::PathExt, ResultExt, TryFutureExt}; use workspace::item::{BreadcrumbText, FollowEvent, FollowableItemHandle}; @@ -824,13 +824,18 @@ impl Item for Editor { .map(|path| path.to_string_lossy().to_string()) .unwrap_or_else(|| "untitled".to_string()); + let settings = ThemeSettings::get_global(cx); + let mut breadcrumbs = vec![BreadcrumbText { text: filename, highlights: None, + font: Some(settings.buffer_font.clone()), }]; + breadcrumbs.extend(symbols.into_iter().map(|symbol| BreadcrumbText { text: symbol.text, highlights: Some(symbol.highlight_ranges), + font: Some(settings.buffer_font.clone()), })); Some(breadcrumbs) } diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index fee4351d5e7eea3185761b79ba39adfbaaf20946..fbf08a93178120493e7a5896d60f050640ad598d 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -866,6 +866,7 @@ impl Item for TerminalView { Some(vec![BreadcrumbText { text: self.terminal().read(cx).breadcrumb_text.clone(), highlights: None, + font: None, }]) } diff --git a/crates/workspace/src/item.rs b/crates/workspace/src/item.rs index 26b46ea3d32ac393648096d314514be3acf45f0f..2340a9db4e8228640266748c6cb1bbd4b3006601 100644 --- a/crates/workspace/src/item.rs +++ b/crates/workspace/src/item.rs @@ -14,7 +14,7 @@ use client::{ use futures::{channel::mpsc, StreamExt}; use gpui::{ AnyElement, AnyView, AppContext, Entity, EntityId, EventEmitter, FocusHandle, FocusableView, - HighlightStyle, Model, Pixels, Point, SharedString, Task, View, ViewContext, WeakView, + Font, HighlightStyle, Model, Pixels, Point, SharedString, Task, View, ViewContext, WeakView, WindowContext, }; use project::{Project, ProjectEntryId, ProjectPath}; @@ -93,6 +93,7 @@ pub enum ItemEvent { pub struct BreadcrumbText { pub text: String, pub highlights: Option, HighlightStyle)>>, + pub font: Option, } pub trait Item: FocusableView + EventEmitter {