Overhaul handling of font families

* Specify font families in the theme.
* Load fonts eagerly when loading themes, instead of loading
  them lazily when rendering.

Co-Authored-By: Antonio Scandurra <me@as-cii.com>
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld
2021-08-26 15:06:00 -07:00
co-authored by Antonio Scandurra Nathan Sobo
parent ee9ee294ad
commit 3bb5610ad1
23 changed files with 438 additions and 397 deletions
+33 -18
View File
@@ -343,8 +343,8 @@ mod tests {
use crate::{
editor::movement,
language::{Language, LanguageConfig},
settings::Theme,
test::*,
theme::SyntaxTheme,
util::RandomCharIter,
};
use buffer::{History, SelectionGoal};
@@ -366,7 +366,7 @@ mod tests {
tab_size: rng.gen_range(1..=4),
buffer_font_family: font_cache.load_family(&["Helvetica"]).unwrap(),
buffer_font_size: 14.0,
..Settings::new(&font_cache).unwrap()
..cx.read(Settings::test)
};
let max_wrap_width = 300.0;
let mut wrap_width = if rng.gen_bool(0.1) {
@@ -535,7 +535,7 @@ mod tests {
buffer_font_size: 12.0,
ui_font_size: 12.0,
tab_size: 4,
theme: Arc::new(Theme::default()),
..cx.read(Settings::test)
};
let wrap_width = Some(64.);
@@ -606,7 +606,10 @@ mod tests {
let map = cx.add_model(|cx| {
DisplayMap::new(
buffer.clone(),
Settings::new(cx.font_cache()).unwrap().with_tab_size(4),
Settings {
tab_size: 4,
..Settings::test(cx)
},
None,
cx,
)
@@ -660,13 +663,13 @@ mod tests {
(function_item name: (identifier) @fn.name)"#,
)
.unwrap();
let theme = Theme {
syntax: vec![
let theme = SyntaxTheme::new(
Default::default(),
vec![
("mod.body".to_string(), Color::from_u32(0xff0000ff).into()),
("fn.name".to_string(), Color::from_u32(0x00ff00ff).into()),
],
..Default::default()
};
);
let lang = Arc::new(Language {
config: LanguageConfig {
name: "Test".to_string(),
@@ -688,7 +691,10 @@ mod tests {
let map = cx.add_model(|cx| {
DisplayMap::new(
buffer,
Settings::new(cx.font_cache()).unwrap().with_tab_size(2),
Settings {
tab_size: 2,
..Settings::test(cx)
},
None,
cx,
)
@@ -750,13 +756,13 @@ mod tests {
(function_item name: (identifier) @fn.name)"#,
)
.unwrap();
let theme = Theme {
syntax: vec![
let theme = SyntaxTheme::new(
Default::default(),
vec![
("mod.body".to_string(), Color::from_u32(0xff0000ff).into()),
("fn.name".to_string(), Color::from_u32(0x00ff00ff).into()),
],
..Default::default()
};
);
let lang = Arc::new(Language {
config: LanguageConfig {
name: "Test".to_string(),
@@ -780,7 +786,7 @@ mod tests {
tab_size: 4,
buffer_font_family: font_cache.load_family(&["Courier"]).unwrap(),
buffer_font_size: 16.0,
..Settings::new(&font_cache).unwrap()
..cx.read(Settings::test)
};
let map = cx.add_model(|cx| DisplayMap::new(buffer, settings, Some(40.0), cx));
assert_eq!(
@@ -820,7 +826,10 @@ mod tests {
let map = cx.add_model(|cx| {
DisplayMap::new(
buffer.clone(),
Settings::new(cx.font_cache()).unwrap().with_tab_size(4),
Settings {
tab_size: 4,
..Settings::test(cx)
},
None,
cx,
)
@@ -861,7 +870,10 @@ mod tests {
let map = cx.add_model(|cx| {
DisplayMap::new(
buffer.clone(),
Settings::new(cx.font_cache()).unwrap().with_tab_size(4),
Settings {
tab_size: 4,
..Settings::test(cx)
},
None,
cx,
)
@@ -925,7 +937,10 @@ mod tests {
let map = cx.add_model(|cx| {
DisplayMap::new(
buffer.clone(),
Settings::new(cx.font_cache()).unwrap().with_tab_size(4),
Settings {
tab_size: 4,
..Settings::test(cx)
},
None,
cx,
)
@@ -939,7 +954,7 @@ mod tests {
fn highlighted_chunks<'a>(
rows: Range<u32>,
map: &ModelHandle<DisplayMap>,
theme: &'a Theme,
theme: &'a SyntaxTheme,
cx: &mut MutableAppContext,
) -> Vec<(String, Option<&'a str>)> {
let mut snapshot = map.update(cx, |map, cx| map.snapshot(cx));
+1 -1
View File
@@ -921,7 +921,7 @@ mod tests {
tab_size: rng.gen_range(1..=4),
buffer_font_family: font_cache.load_family(&["Helvetica"]).unwrap(),
buffer_font_size: 14.0,
..Settings::new(&font_cache).unwrap()
..cx.read(Settings::test)
};
log::info!("Tab size: {}", settings.tab_size);
log::info!("Wrap width: {:?}", wrap_width);
+2 -2
View File
@@ -182,12 +182,12 @@ mod tests {
use super::*;
use crate::{
editor::{display_map::DisplayMap, Buffer},
test::build_app_state,
test::test_app_state,
};
#[gpui::test]
fn test_prev_next_word_boundary_multibyte(cx: &mut gpui::MutableAppContext) {
let settings = build_app_state(cx).settings.borrow().clone();
let settings = test_app_state(cx).settings.borrow().clone();
let buffer = cx.add_model(|cx| Buffer::new(0, "a bcΔ defγ", cx));
let display_map = cx.add_model(|cx| DisplayMap::new(buffer, settings, None, cx));
let snapshot = display_map.update(cx, |map, cx| map.snapshot(cx));