Improve importing font-family settings from VS Code (#39736)

Closes https://github.com/zed-industries/zed/issues/39259

- Fixes import of `editor.fontFamily` (we were looking for the wrong
key)
- Adds basic support for the CSS font-family syntax used by VS Code,
including font fallback

Release Notes:

- N/A
This commit is contained in:
John Tur
2025-10-08 19:19:48 -04:00
committed by GitHub
parent 3d0312f4c7
commit ef839cc207
5 changed files with 110 additions and 8 deletions
+51
View File
@@ -4,6 +4,8 @@ use paths::{cursor_settings_file_paths, vscode_settings_file_paths};
use serde_json::{Map, Value};
use std::{path::Path, sync::Arc};
use crate::FontFamilyName;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum VsCodeSettingsSource {
VsCode,
@@ -145,4 +147,53 @@ impl VsCodeSettings {
pub fn read_enum<T>(&self, key: &str, f: impl FnOnce(&str) -> Option<T>) -> Option<T> {
self.content.get(key).and_then(Value::as_str).and_then(f)
}
pub fn font_family_setting(
&self,
key: &str,
font_family: &mut Option<FontFamilyName>,
font_fallbacks: &mut Option<Vec<FontFamilyName>>,
) {
let Some(css_name) = self.content.get(key).and_then(Value::as_str) else {
return;
};
let mut name_buffer = String::new();
let mut quote_char: Option<char> = None;
let mut fonts = Vec::new();
let mut add_font = |buffer: &mut String| {
let trimmed = buffer.trim();
if !trimmed.is_empty() {
fonts.push(trimmed.to_string().into());
}
buffer.clear();
};
for ch in css_name.chars() {
match (ch, quote_char) {
('"' | '\'', None) => {
quote_char = Some(ch);
}
(_, Some(q)) if ch == q => {
quote_char = None;
}
(',', None) => {
add_font(&mut name_buffer);
}
_ => {
name_buffer.push(ch);
}
}
}
add_font(&mut name_buffer);
let mut iter = fonts.into_iter();
*font_family = iter.next();
let fallbacks: Vec<_> = iter.collect();
if !fallbacks.is_empty() {
*font_fallbacks = Some(fallbacks);
}
}
}