Provide editor styling information separately from editor settings
* Since regular editors' font sizes and families are controlled by the settings and not the theme, don't store a dummy text style in the theme. Instead, only store a font color, and synthesize the text style for regular editors using both the theme and the settings. * Style single-line and auto-height editors (now called "field editors") using a single function that takes the entire theme and selects a relevant sub-object. Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
39ebaebd83
commit
47b654063e
18 changed files with 377 additions and 556 deletions
|
@ -1,12 +1,12 @@
|
|||
use crate::{assets::Assets, build_window_options, build_workspace, AppState};
|
||||
use client::{test::FakeHttpClient, ChannelList, Client, UserStore};
|
||||
use gpui::{AssetSource, MutableAppContext};
|
||||
use gpui::MutableAppContext;
|
||||
use language::LanguageRegistry;
|
||||
use parking_lot::Mutex;
|
||||
use postage::watch;
|
||||
use project::fs::FakeFs;
|
||||
use std::sync::Arc;
|
||||
use theme::{Theme, ThemeRegistry, DEFAULT_THEME_NAME};
|
||||
use theme::ThemeRegistry;
|
||||
use workspace::Settings;
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -20,7 +20,7 @@ fn init_logger() {
|
|||
pub fn test_app_state(cx: &mut MutableAppContext) -> Arc<AppState> {
|
||||
let mut path_openers = Vec::new();
|
||||
editor::init(cx, &mut path_openers);
|
||||
let (settings_tx, settings) = watch::channel_with(build_settings(cx));
|
||||
let (settings_tx, settings) = watch::channel_with(Settings::test(cx));
|
||||
let themes = ThemeRegistry::new(Assets, cx.font_cache().clone());
|
||||
let http = FakeHttpClient::with_404_response();
|
||||
let client = Client::new(http.clone());
|
||||
|
@ -48,27 +48,3 @@ pub fn test_app_state(cx: &mut MutableAppContext) -> Arc<AppState> {
|
|||
build_workspace: &build_workspace,
|
||||
})
|
||||
}
|
||||
|
||||
fn build_settings(cx: &gpui::AppContext) -> Settings {
|
||||
lazy_static::lazy_static! {
|
||||
static ref DEFAULT_THEME: parking_lot::Mutex<Option<Arc<Theme>>> = Default::default();
|
||||
static ref FONTS: Vec<Arc<Vec<u8>>> = vec![
|
||||
Assets.load("fonts/zed-sans/zed-sans-regular.ttf").unwrap().to_vec().into()
|
||||
];
|
||||
}
|
||||
|
||||
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(Assets, cx.font_cache().clone())
|
||||
.get(DEFAULT_THEME_NAME)
|
||||
.expect("failed to load default theme in tests");
|
||||
*theme_guard = Some(theme.clone());
|
||||
theme
|
||||
};
|
||||
|
||||
Settings::new("Zed Sans", cx.font_cache(), theme).unwrap()
|
||||
}
|
||||
|
|
|
@ -133,9 +133,11 @@ fn quit(_: &Quit, cx: &mut gpui::MutableAppContext) {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::assets::Assets;
|
||||
|
||||
use super::*;
|
||||
use editor::{DisplayPoint, Editor};
|
||||
use gpui::{MutableAppContext, TestAppContext, ViewHandle};
|
||||
use gpui::{AssetSource, MutableAppContext, TestAppContext, ViewHandle};
|
||||
use project::{Fs, ProjectPath};
|
||||
use serde_json::json;
|
||||
use std::{
|
||||
|
@ -143,7 +145,7 @@ mod tests {
|
|||
path::{Path, PathBuf},
|
||||
};
|
||||
use test::test_app_state;
|
||||
use theme::DEFAULT_THEME_NAME;
|
||||
use theme::{Theme, ThemeRegistry, DEFAULT_THEME_NAME};
|
||||
use util::test::temp_tree;
|
||||
use workspace::{
|
||||
open_paths, pane, ItemView, ItemViewHandle, OpenNew, Pane, SplitDirection, WorkspaceHandle,
|
||||
|
@ -862,10 +864,20 @@ mod tests {
|
|||
|
||||
#[gpui::test]
|
||||
fn test_bundled_themes(cx: &mut MutableAppContext) {
|
||||
let app_state = test_app_state(cx);
|
||||
let themes = ThemeRegistry::new(Assets, cx.font_cache().clone());
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref DEFAULT_THEME: parking_lot::Mutex<Option<Arc<Theme>>> = Default::default();
|
||||
static ref FONTS: Vec<Arc<Vec<u8>>> = vec![
|
||||
Assets.load("fonts/zed-sans/zed-sans-regular.ttf").unwrap().to_vec().into()
|
||||
];
|
||||
}
|
||||
|
||||
cx.platform().fonts().add_fonts(&FONTS).unwrap();
|
||||
|
||||
let mut has_default_theme = false;
|
||||
for theme_name in app_state.themes.list() {
|
||||
let theme = app_state.themes.get(&theme_name).unwrap();
|
||||
for theme_name in themes.list() {
|
||||
let theme = themes.get(&theme_name).unwrap();
|
||||
if theme.name == DEFAULT_THEME_NAME {
|
||||
has_default_theme = true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue