mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 06:59:22 +01:00
Make mermaid diagram font family configurable (#63430)
# Objective Fix #63428 ## Solution Add a settings option `"mermaid_font_family"` to allow escape from `"ui_font_family"`. Does not affect any default behavior. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable ## Showcase <img width="2426" height="1456" alt="Image" src="https://github.com/user-attachments/assets/70ec2ae3-a184-4523-bce2-272c8f33b840" /> <img width="1838" height="668" alt="image" src="https://github.com/user-attachments/assets/93711957-8f9c-42cd-afc0-a1ac84f1d7a3" /> Release Notes: - Make mermaid diagram font family configurable to fix #63428 Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -370,7 +370,7 @@ fn build_mermaid_theme(cx: &Context<Markdown>) -> 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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -214,6 +214,9 @@ pub struct ThemeSettingsContent {
|
||||
/// The font size for user messages in the agent panel.
|
||||
pub agent_buffer_font_size: Option<FontSize>,
|
||||
pub git_commit_buffer_font_size: Option<FontSize>,
|
||||
/// 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<FontFamilyName>,
|
||||
/// The name of the Zed theme to use.
|
||||
pub theme: Option<ThemeSelection>,
|
||||
/// The name of the icon theme to use.
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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<ThemeSelection>,
|
||||
/// The font family used for Mermaid diagrams.
|
||||
/// Falls back to the UI font family if unset.
|
||||
mermaid_font_family: Option<SharedString>,
|
||||
/// 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())
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user