Flip the dependency between editor and theme

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Antonio Scandurra 2021-10-05 19:21:13 +02:00
parent f09798c4a7
commit f70e3878b6
12 changed files with 94 additions and 94 deletions

View file

@ -358,10 +358,11 @@ impl ToDisplayPoint for Anchor {
mod tests {
use super::*;
use crate::{movement, test::*};
use buffer::{History, Language, LanguageConfig, RandomCharIter, SelectionGoal, SyntaxTheme};
use buffer::{History, Language, LanguageConfig, RandomCharIter, SelectionGoal};
use gpui::{color::Color, MutableAppContext};
use rand::{prelude::StdRng, Rng};
use std::{env, sync::Arc};
use theme::SyntaxTheme;
use Bias::*;
#[gpui::test(iterations = 100)]
@ -976,7 +977,7 @@ mod tests {
let mut snapshot = map.update(cx, |map, cx| map.snapshot(cx));
let mut chunks: Vec<(String, Option<&str>)> = Vec::new();
for (chunk, style_id) in snapshot.highlighted_chunks_for_rows(rows) {
let style_name = theme.highlight_name(style_id);
let style_name = style_id.name(theme);
if let Some((last_chunk, last_style_name)) = chunks.last_mut() {
if style_name == *last_style_name {
last_chunk.push_str(chunk);

View file

@ -513,9 +513,8 @@ impl EditorElement {
}
if !line_chunk.is_empty() && !line_exceeded_max_len {
let highlight_style = style
.syntax
.highlight_style(style_ix)
let highlight_style = style_ix
.style(&style.syntax)
.unwrap_or(style.text.clone().into());
// Avoid a lookup if the font properties match the previous ones.
let font_id = if highlight_style.font_properties == prev_font_properties {

View file

@ -28,6 +28,7 @@ use std::{
time::Duration,
};
use sum_tree::Bias;
use theme::EditorStyle;
use util::post_inc;
const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
@ -283,27 +284,6 @@ pub struct EditorSettings {
pub style: EditorStyle,
}
#[derive(Clone, Deserialize, Default)]
pub struct EditorStyle {
pub text: TextStyle,
#[serde(default)]
pub placeholder_text: Option<TextStyle>,
pub background: Color,
pub selection: SelectionStyle,
pub gutter_background: Color,
pub active_line_background: Color,
pub line_number: Color,
pub line_number_active: Color,
pub guest_selections: Vec<SelectionStyle>,
pub syntax: Arc<SyntaxTheme>,
}
#[derive(Clone, Copy, Default, Deserialize)]
pub struct SelectionStyle {
pub cursor: Color,
pub selection: Color,
}
pub struct Editor {
handle: WeakViewHandle<Self>,
buffer: ModelHandle<Buffer>,
@ -2448,12 +2428,6 @@ impl Snapshot {
}
}
impl EditorStyle {
fn placeholder_text(&self) -> &TextStyle {
self.placeholder_text.as_ref().unwrap_or(&self.text)
}
}
impl EditorSettings {
#[cfg(any(test, feature = "test-support"))]
pub fn test(cx: &AppContext) -> Self {