diff --git a/assets/settings/default.json b/assets/settings/default.json index 0a926bdd0df..29ef750de27 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -79,6 +79,9 @@ "agent_buffer_font_size": 12, // The default font size for the commit editor in the git panel and commit modal. "git_commit_buffer_font_size": 12, + // The font family for Mermaid diagrams in the agent panel and markdown preview. + // Falls back to the UI font family if unset. + "mermaid_font_family": null, // How much to fade out unused code. "unnecessary_code_fade": 0.3, // Active pane styling settings. diff --git a/crates/markdown/src/mermaid.rs b/crates/markdown/src/mermaid.rs index 0d4bc76108c..63aae2aacbb 100644 --- a/crates/markdown/src/mermaid.rs +++ b/crates/markdown/src/mermaid.rs @@ -370,7 +370,7 @@ fn build_mermaid_theme(cx: &Context) -> mermaid_render::MermaidTheme { mermaid_render::MermaidTheme { dark_mode: is_dark, - font_family: mermaid_font_family(theme_settings.ui_font.family.as_ref()), + font_family: mermaid_font_family(theme_settings.mermaid_font_family().as_ref()), background: colors.editor_background, primary_color: colors.surface_background, primary_text_color: colors.text, diff --git a/crates/settings/src/vscode_import.rs b/crates/settings/src/vscode_import.rs index 9f4f835824d..8f6e81ec696 100644 --- a/crates/settings/src/vscode_import.rs +++ b/crates/settings/src/vscode_import.rs @@ -1037,6 +1037,7 @@ impl VsCodeSettings { agent_buffer_font_family: None, agent_buffer_font_size: None, git_commit_buffer_font_size: None, + mermaid_font_family: None, theme: None, icon_theme: None, ui_density: None, diff --git a/crates/settings_content/src/theme.rs b/crates/settings_content/src/theme.rs index 157d1384557..0b2b7106091 100644 --- a/crates/settings_content/src/theme.rs +++ b/crates/settings_content/src/theme.rs @@ -214,6 +214,9 @@ pub struct ThemeSettingsContent { /// The font size for user messages in the agent panel. pub agent_buffer_font_size: Option, pub git_commit_buffer_font_size: Option, + /// The name of a font to use for rendering Mermaid diagrams in the agent + /// panel and markdown preview. Falls back to the UI font if unset. + pub mermaid_font_family: Option, /// The name of the Zed theme to use. pub theme: Option, /// The name of the icon theme to use. diff --git a/crates/settings_ui/src/page_data.rs b/crates/settings_ui/src/page_data.rs index 9da1f4fc4f4..85736191915 100644 --- a/crates/settings_ui/src/page_data.rs +++ b/crates/settings_ui/src/page_data.rs @@ -1365,6 +1365,32 @@ fn appearance_page() -> SettingsPage { ] } + fn mermaid_font_section() -> [SettingsPageItem; 2] { + [ + SettingsPageItem::SectionHeader("Mermaid Font"), + SettingsPageItem::SettingItem(SettingItem { + title: "Font Family", + description: "Font family for Mermaid diagrams in the agent panel and markdown preview. Falls back to the UI font family.", + field: Box::new(SettingField { + organization_override: None, + json_path: Some("mermaid_font_family"), + pick: |settings_content| { + settings_content + .theme + .mermaid_font_family + .as_ref() + .or(settings_content.theme.ui_font_family.as_ref()) + }, + write: |settings_content, value, _| { + settings_content.theme.mermaid_font_family = value; + }, + }), + metadata: None, + files: USER, + }), + ] + } + fn text_rendering_section() -> [SettingsPageItem; 2] { [ SettingsPageItem::SectionHeader("Text Rendering"), @@ -1633,6 +1659,7 @@ fn appearance_page() -> SettingsPage { ui_font_section(), agent_panel_font_section(), markdown_preview_font_section(), + mermaid_font_section(), text_rendering_section(), cursor_section(), highlighting_section(), diff --git a/crates/theme_settings/src/settings.rs b/crates/theme_settings/src/settings.rs index 76213f33355..0a587340f5b 100644 --- a/crates/theme_settings/src/settings.rs +++ b/crates/theme_settings/src/settings.rs @@ -75,6 +75,9 @@ pub struct ThemeSettings { /// The theme to use for the markdown preview. /// Falls back to the main editor theme if unset. pub markdown_preview_theme: Option, + /// The font family used for Mermaid diagrams. + /// Falls back to the UI font family if unset. + mermaid_font_family: Option, /// The font weight for headings in the markdown preview. markdown_preview_heading_font_weight: FontWeight, /// The line height for buffers, and the terminal. @@ -444,6 +447,14 @@ impl ThemeSettings { .unwrap_or(&self.buffer_font.family) } + /// Returns the font family to use for Mermaid diagrams, + /// falling back to the UI font family when unset. + pub fn mermaid_font_family(&self) -> &SharedString { + self.mermaid_font_family + .as_ref() + .unwrap_or(&self.ui_font.family) + } + /// Returns the font weight to use for headings in the markdown preview. pub fn markdown_preview_heading_font_weight(&self) -> FontWeight { self.markdown_preview_heading_font_weight @@ -763,6 +774,10 @@ impl settings::Settings for ThemeSettings { markdown_preview_theme: markdown_preview .and_then(|preview| preview.theme.clone()) .map(ThemeSelection::from), + mermaid_font_family: content + .mermaid_font_family + .as_ref() + .map(|font| font.0.clone().into()), markdown_preview_heading_font_weight: markdown_preview .and_then(|preview| preview.heading_font_weight) .map(|weight| weight.into_gpui()) diff --git a/docs/src/visual-customization.md b/docs/src/visual-customization.md index e08f38cfeb8..3ab4692c3fd 100644 --- a/docs/src/visual-customization.md +++ b/docs/src/visual-customization.md @@ -78,6 +78,10 @@ If you would like to use distinct themes for light mode/dark mode that can be se // and any other snippet of code. "agent_buffer_font_size": 12, + // Controls the font family for Mermaid diagrams in the agent panel and + // markdown preview. If not specified, it falls back to the UI font family. + "mermaid_font_family": "Inter", + "markdown_preview": { // Controls the font size for the markdown preview. // If not specified, it falls back to the editor font size.