From c21b754c4c197e8a888182acb094fd9a0fd427a4 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 16 Sep 2021 13:23:42 -0600 Subject: [PATCH] Make placeholder text style optional --- zed/src/editor.rs | 18 ++++++++++-------- zed/src/theme.rs | 3 ++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/zed/src/editor.rs b/zed/src/editor.rs index fe4677db5f10b4afe4e883cd45ef094ba183d817..15a312ce5f22122a94b5c9fa862e28e2dfdfb924 100644 --- a/zed/src/editor.rs +++ b/zed/src/editor.rs @@ -282,7 +282,7 @@ pub enum EditorMode { pub struct EditorStyle { pub text: HighlightStyle, #[serde(default)] - pub placeholder_text: HighlightStyle, + pub placeholder_text: Option, pub background: Color, pub selection: SelectionStyle, pub gutter_background: Color, @@ -2468,7 +2468,7 @@ impl Snapshot { .skip(rows.start as usize) .take(rows.len()); let font_id = font_cache - .select_font(self.font_family, &style.placeholder_text.font_properties)?; + .select_font(self.font_family, &style.placeholder_text().font_properties)?; return Ok(placeholder_lines .into_iter() .map(|line| { @@ -2479,7 +2479,7 @@ impl Snapshot { line.len(), RunStyle { font_id, - color: style.placeholder_text.color, + color: style.placeholder_text().color, underline: false, }, )], @@ -2596,6 +2596,12 @@ impl Snapshot { } } +impl EditorStyle { + fn placeholder_text(&self) -> &HighlightStyle { + self.placeholder_text.as_ref().unwrap_or(&self.text) + } +} + impl Default for EditorStyle { fn default() -> Self { Self { @@ -2604,11 +2610,7 @@ impl Default for EditorStyle { font_properties: Default::default(), underline: false, }, - placeholder_text: HighlightStyle { - color: Color::from_u32(0x00ff00ff), - font_properties: Default::default(), - underline: false, - }, + placeholder_text: None, background: Default::default(), gutter_background: Default::default(), active_line_background: Default::default(), diff --git a/zed/src/theme.rs b/zed/src/theme.rs index cf89173d8b847c106e5337ea7abddfd5530b78a7..52e1b0d0a8478e63ab507e38a506a5421f69efd9 100644 --- a/zed/src/theme.rs +++ b/zed/src/theme.rs @@ -164,7 +164,8 @@ pub struct InputEditorStyle { #[serde(flatten)] pub container: ContainerStyle, pub text: HighlightStyle, - pub placeholder_text: HighlightStyle, + #[serde(default)] + pub placeholder_text: Option, pub selection: SelectionStyle, }