Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
markdown: Use buffer font instead of UI font for code blocks (#17351)
Mathiasa1c676128a5a
diff --git a/Cargo.lock b/Cargo.lockindex 7b1754966df..20b9f4ab2d9 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -6678,6 +6678,7 @@ dependencies = ["log","pretty_assertions","pulldown-cmark 0.12.1",+ "settings","theme","ui","workspace",diff --git a/crates/markdown_preview/Cargo.toml b/crates/markdown_preview/Cargo.tomlindex e1e514a63ed..46a33966f2b 100644--- a/crates/markdown_preview/Cargo.toml+++ b/crates/markdown_preview/Cargo.toml@@ -25,6 +25,7 @@ linkify.workspace = truelog.workspace = truepretty_assertions.workspace = truepulldown-cmark.workspace = true+settings.workspace = truetheme.workspace = trueui.workspace = trueworkspace.workspace = truediff --git a/crates/markdown_preview/src/markdown_renderer.rs b/crates/markdown_preview/src/markdown_renderer.rsindex 4de654e46ac..6e092e540cf 100644--- a/crates/markdown_preview/src/markdown_renderer.rs+++ b/crates/markdown_preview/src/markdown_renderer.rs@@ -9,11 +9,12 @@ use gpui::{HighlightStyle, Hsla, InteractiveText, IntoElement, Keystroke, Modifiers, ParentElement,SharedString, Styled, StyledText, TextStyle, WeakView, WindowContext,};+use settings::Settings;use std::{ops::{Mul, Range},sync::Arc,};-use theme::{ActiveTheme, SyntaxTheme};+use theme::{ActiveTheme, SyntaxTheme, ThemeSettings};use ui::{h_flex, v_flex, Checkbox, FluentBuilder, InteractiveElement, LinkPreview, Selection,StatefulInteractiveElement, Tooltip,@@ -25,6 +26,8 @@ type CheckboxClickedCallback = Arc<Box<dyn Fn(bool, Range<usize>, &mut WindowConpub struct RenderContext {workspace: Option<WeakView<Workspace>>,next_id: usize,+ buffer_font_family: SharedString,+ buffer_text_style: TextStyle,text_style: TextStyle,border_color: Hsla,text_color: Hsla,@@ -40,10 +43,17 @@ impl RenderContext {pub fn new(workspace: Option<WeakView<Workspace>>, cx: &WindowContext) -> RenderContext {let theme = cx.theme().clone();+ let settings = ThemeSettings::get_global(cx);+ let buffer_font_family = settings.buffer_font.family.clone();+ let mut buffer_text_style = cx.text_style();+ buffer_text_style.font_family = buffer_font_family.clone();+RenderContext {workspace,next_id: 0,indent: 0,+ buffer_font_family,+ buffer_text_style,text_style: cx.text_style(),syntax_theme: theme.syntax().clone(),border_color: theme.colors().border,@@ -308,7 +318,7 @@ fn render_markdown_code_block() -> AnyElement {let body = if let Some(highlights) = parsed.highlights.as_ref() {StyledText::new(parsed.contents.clone()).with_highlights(- &cx.text_style,+ &cx.buffer_text_style,highlights.iter().filter_map(|(range, highlight_id)| {highlight_id.style(cx.syntax_theme.as_ref())@@ -320,6 +330,7 @@ fn render_markdown_code_block(};cx.with_common_p(div())+ .font_family(cx.buffer_font_family.clone()).px_3().py_3().bg(cx.code_block_background_color)