From ad9712db7034308b0c27bf2c6fdc08963c96fa8d Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 16 Sep 2021 12:26:18 -0600 Subject: [PATCH] Move EditorStyle into editor module --- zed/src/editor.rs | 48 +++++++++++++++++++++++++++++++++++++-- zed/src/editor/element.rs | 6 +++-- zed/src/theme.rs | 45 +----------------------------------- 3 files changed, 51 insertions(+), 48 deletions(-) diff --git a/zed/src/editor.rs b/zed/src/editor.rs index 3157b0cd2fbb28010d13d2b6ab5da4ec4ba35f6c..8926d5afd5074e5cc34563e0ee571fca3d958a0d 100644 --- a/zed/src/editor.rs +++ b/zed/src/editor.rs @@ -5,7 +5,7 @@ pub mod movement; use crate::{ settings::{HighlightId, Settings}, - theme::{EditorStyle, Theme}, + theme::Theme, time::ReplicaId, util::{post_inc, Bias}, workspace, @@ -20,7 +20,7 @@ use gpui::{ action, color::Color, font_cache::FamilyId, - fonts::Properties as FontProperties, + fonts::{HighlightStyle, Properties as FontProperties}, geometry::vector::Vector2F, keymap::Binding, text_layout::{self, RunStyle}, @@ -278,6 +278,26 @@ pub enum EditorMode { Full, } +#[derive(Clone, Deserialize)] +pub struct EditorStyle { + pub text: HighlightStyle, + #[serde(default)] + pub placeholder_text: HighlightStyle, + 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, +} + +#[derive(Clone, Copy, Default, Deserialize)] +pub struct SelectionStyle { + pub cursor: Color, + pub selection: Color, +} + pub struct Editor { handle: WeakViewHandle, buffer: ModelHandle, @@ -2569,6 +2589,30 @@ impl Snapshot { } } +impl Default for EditorStyle { + fn default() -> Self { + Self { + text: HighlightStyle { + color: Color::from_u32(0xff0000ff), + font_properties: Default::default(), + underline: false, + }, + placeholder_text: HighlightStyle { + color: Color::from_u32(0x00ff00ff), + font_properties: Default::default(), + underline: false, + }, + background: Default::default(), + gutter_background: Default::default(), + active_line_background: Default::default(), + line_number: Default::default(), + line_number_active: Default::default(), + selection: Default::default(), + guest_selections: Default::default(), + } + } +} + fn compute_scroll_position( snapshot: &DisplayMapSnapshot, mut scroll_position: Vector2F, diff --git a/zed/src/editor/element.rs b/zed/src/editor/element.rs index 8ab6c52cc5fcf9d15027a0940fbb08cbb6c2414a..2dec968d78d67de9d9e30c20e6a7fd455915ab4a 100644 --- a/zed/src/editor/element.rs +++ b/zed/src/editor/element.rs @@ -1,5 +1,7 @@ -use super::{DisplayPoint, Editor, EditorMode, Insert, Scroll, Select, SelectPhase, Snapshot}; -use crate::{theme::EditorStyle, time::ReplicaId}; +use super::{ + DisplayPoint, Editor, EditorMode, EditorStyle, Insert, Scroll, Select, SelectPhase, Snapshot, +}; +use crate::time::ReplicaId; use gpui::{ color::Color, geometry::{ diff --git a/zed/src/theme.rs b/zed/src/theme.rs index a96945fecc1011d9c1de9ef941560f863350491d..cf89173d8b847c106e5337ea7abddfd5530b78a7 100644 --- a/zed/src/theme.rs +++ b/zed/src/theme.rs @@ -2,6 +2,7 @@ mod highlight_map; mod resolution; mod theme_registry; +use crate::editor::{EditorStyle, SelectionStyle}; use anyhow::Result; use gpui::{ color::Color, @@ -158,20 +159,6 @@ pub struct ContainedLabel { pub label: LabelStyle, } -#[derive(Clone, Deserialize)] -pub struct EditorStyle { - pub text: HighlightStyle, - #[serde(default)] - pub placeholder_text: HighlightStyle, - 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, -} - #[derive(Clone, Deserialize)] pub struct InputEditorStyle { #[serde(flatten)] @@ -181,12 +168,6 @@ pub struct InputEditorStyle { pub selection: SelectionStyle, } -#[derive(Clone, Copy, Default, Deserialize)] -pub struct SelectionStyle { - pub cursor: Color, - pub selection: Color, -} - impl SyntaxTheme { pub fn new(highlights: Vec<(String, HighlightStyle)>) -> Self { Self { highlights } @@ -204,30 +185,6 @@ impl SyntaxTheme { } } -impl Default for EditorStyle { - fn default() -> Self { - Self { - text: HighlightStyle { - color: Color::from_u32(0xff0000ff), - font_properties: Default::default(), - underline: false, - }, - placeholder_text: HighlightStyle { - color: Color::from_u32(0x00ff00ff), - font_properties: Default::default(), - underline: false, - }, - background: Default::default(), - gutter_background: Default::default(), - active_line_background: Default::default(), - line_number: Default::default(), - line_number_active: Default::default(), - selection: Default::default(), - guest_selections: Default::default(), - } - } -} - impl InputEditorStyle { pub fn as_editor(&self) -> EditorStyle { EditorStyle {