diff --git a/gpui/src/platform.rs b/gpui/src/platform.rs index 078bf7970560c1c4eca8f99517ddf43526f4f5c3..ba237d47882b2c9fe7d57586b929b2df72729ce1 100644 --- a/gpui/src/platform.rs +++ b/gpui/src/platform.rs @@ -128,7 +128,7 @@ pub enum CursorStyle { } pub trait FontSystem: Send + Sync { - fn add_fonts(&self, fonts: Vec>>) -> anyhow::Result<()>; + fn add_fonts(&self, fonts: &[Arc>]) -> anyhow::Result<()>; fn load_family(&self, name: &str) -> anyhow::Result>; fn select_font( &self, diff --git a/gpui/src/platform/mac/fonts.rs b/gpui/src/platform/mac/fonts.rs index 8f61bfab30bdf4c26055221aa5e9c568a987f942..4b2716c0442f4bc0f4413d2ec6be4aa209b55393 100644 --- a/gpui/src/platform/mac/fonts.rs +++ b/gpui/src/platform/mac/fonts.rs @@ -50,7 +50,7 @@ impl FontSystem { } impl platform::FontSystem for FontSystem { - fn add_fonts(&self, fonts: Vec>>) -> anyhow::Result<()> { + fn add_fonts(&self, fonts: &[Arc>]) -> anyhow::Result<()> { self.0.write().add_fonts(fonts) } @@ -102,9 +102,12 @@ impl platform::FontSystem for FontSystem { } impl FontSystemState { - fn add_fonts(&mut self, fonts: Vec>>) -> anyhow::Result<()> { - self.memory_source - .add_fonts(fonts.into_iter().map(|bytes| Handle::from_memory(bytes, 0)))?; + fn add_fonts(&mut self, fonts: &[Arc>]) -> anyhow::Result<()> { + self.memory_source.add_fonts( + fonts + .iter() + .map(|bytes| Handle::from_memory(bytes.clone(), 0)), + )?; Ok(()) } diff --git a/zed/src/editor.rs b/zed/src/editor.rs index 63ebe9982f9b27da9e91cc06840a12ad865761fb..2d4b763776d3cb3d1749cb294575e1167a178ae5 100644 --- a/zed/src/editor.rs +++ b/zed/src/editor.rs @@ -3478,7 +3478,7 @@ mod tests { }); view.update(cx, |view, cx| { - view.set_wrap_width(140., cx); + view.set_wrap_width(130., cx); assert_eq!( view.display_text(cx), "use one::{\n two::three::\n four::five\n};" diff --git a/zed/src/main.rs b/zed/src/main.rs index 3603e760eb07f06e899dab538126ea49df44eb08..5ad05738e6935496ca9b02d45190c93cc18e7725 100644 --- a/zed/src/main.rs +++ b/zed/src/main.rs @@ -27,8 +27,8 @@ fn main() { .list("fonts") .into_iter() .map(|f| Arc::new(Assets.load(&f).unwrap().to_vec())) - .collect(); - app.platform().fonts().add_fonts(embedded_fonts).unwrap(); + .collect::>(); + app.platform().fonts().add_fonts(&embedded_fonts).unwrap(); let themes = settings::ThemeRegistry::new(Assets, app.font_cache()); let (settings_tx, settings) = settings::channel(&app.font_cache(), &themes).unwrap(); diff --git a/zed/src/settings.rs b/zed/src/settings.rs index 6b7defe1361db50a6ca818a55dd88841c2bc4dc0..8893e8bd9f430e84a66c082470605d2f6b7ed95d 100644 --- a/zed/src/settings.rs +++ b/zed/src/settings.rs @@ -17,15 +17,25 @@ pub struct Settings { impl Settings { #[cfg(any(test, feature = "test-support"))] pub fn test(cx: &gpui::AppContext) -> Self { + use crate::assets::Assets; + use gpui::AssetSource; + lazy_static::lazy_static! { static ref DEFAULT_THEME: parking_lot::Mutex>> = Default::default(); + static ref FONTS: Vec>> = Assets + .list("fonts") + .into_iter() + .map(|f| Arc::new(Assets.load(&f).unwrap().to_vec())) + .collect(); } + cx.platform().fonts().add_fonts(&FONTS).unwrap(); + let mut theme_guard = DEFAULT_THEME.lock(); let theme = if let Some(theme) = theme_guard.as_ref() { theme.clone() } else { - let theme = ThemeRegistry::new(crate::assets::Assets, cx.font_cache().clone()) + let theme = ThemeRegistry::new(Assets, cx.font_cache().clone()) .get(DEFAULT_THEME_NAME) .expect("failed to load default theme in tests"); *theme_guard = Some(theme.clone()); diff --git a/zed/src/test.rs b/zed/src/test.rs index d8b30afa6923837d935c1fece436a4b01593015e..b917e428f683df23a6b6cd23f51e1c95be849d27 100644 --- a/zed/src/test.rs +++ b/zed/src/test.rs @@ -1,4 +1,5 @@ use crate::{ + assets::Assets, channel::ChannelList, fs::RealFs, language::LanguageRegistry, @@ -158,7 +159,7 @@ fn write_tree(path: &Path, tree: serde_json::Value) { pub fn test_app_state(cx: &mut MutableAppContext) -> Arc { let (settings_tx, settings) = settings::test(cx); let languages = Arc::new(LanguageRegistry::new()); - let themes = ThemeRegistry::new((), cx.font_cache().clone()); + let themes = ThemeRegistry::new(Assets, cx.font_cache().clone()); let rpc = rpc::Client::new(); let user_store = Arc::new(UserStore::new(rpc.clone())); Arc::new(AppState { diff --git a/zed/src/theme/theme_registry.rs b/zed/src/theme/theme_registry.rs index 0808281f09e4b34f99692130c4f75edf39f85d79..cd9781afe942f4e5bee4d1c16b6aa5886ae376a0 100644 --- a/zed/src/theme/theme_registry.rs +++ b/zed/src/theme/theme_registry.rs @@ -515,16 +515,16 @@ fn value_at<'a>(object: &'a mut Map, key_path: &KeyPath) -> Optio #[cfg(test)] mod tests { use super::*; - use crate::{assets::Assets, theme::DEFAULT_THEME_NAME}; + use crate::{test::test_app_state, theme::DEFAULT_THEME_NAME}; use gpui::MutableAppContext; use rand::{prelude::StdRng, Rng}; #[gpui::test] fn test_bundled_themes(cx: &mut MutableAppContext) { - let registry = ThemeRegistry::new(Assets, cx.font_cache().clone()); + let app_state = test_app_state(cx); let mut has_default_theme = false; - for theme_name in registry.list() { - let theme = registry.get(&theme_name).unwrap(); + for theme_name in app_state.themes.list() { + let theme = app_state.themes.get(&theme_name).unwrap(); if theme.name == DEFAULT_THEME_NAME { has_default_theme = true; }