From 1def355d4467021abfcc87bef05f135ac2d1750b Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 15 Nov 2023 09:10:46 +0100 Subject: [PATCH] Don't return `Result` from `TextStyle::highlight` --- crates/editor2/src/display_map.rs | 7 +------ crates/editor2/src/editor.rs | 23 +++++++++-------------- crates/editor2/src/element.rs | 6 +----- crates/gpui2/src/style.rs | 4 ++-- 4 files changed, 13 insertions(+), 27 deletions(-) diff --git a/crates/editor2/src/display_map.rs b/crates/editor2/src/display_map.rs index f808ffa702..d88daaccc1 100644 --- a/crates/editor2/src/display_map.rs +++ b/crates/editor2/src/display_map.rs @@ -578,12 +578,7 @@ impl DisplaySnapshot { line.push_str(chunk.chunk); let text_style = if let Some(style) = chunk.style { - editor_style - .text - .clone() - .highlight(style) - .map(Cow::Owned) - .unwrap_or_else(|_| Cow::Borrowed(&editor_style.text)) + Cow::Owned(editor_style.text.clone().highlight(style)) } else { Cow::Borrowed(&editor_style.text) }; diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index 23dfc9b9d3..b37c5e5756 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -7798,20 +7798,15 @@ impl Editor { render: Arc::new({ let rename_editor = rename_editor.clone(); move |cx: &mut BlockContext| { - let text_style = if let Some(highlight_style) = old_highlight_id + let mut text_style = cx.editor_style.text.clone(); + if let Some(highlight_style) = old_highlight_id .and_then(|h| h.style(&cx.editor_style.syntax)) { - cx.editor_style - .text - .clone() - .highlight(highlight_style) - .unwrap_or_else(|_| cx.editor_style.text.clone()) - } else { - cx.editor_style.text.clone() - }; - div().pl(cx.anchor_x).child(with_view( - &rename_editor, - |_, _| { + text_style = text_style.highlight(highlight_style); + } + div() + .pl(cx.anchor_x) + .child(with_view(&rename_editor, |_, _| { EditorElement::new(EditorStyle { background: cx.theme().system().transparent, local_player: cx.editor_style.local_player, @@ -7823,8 +7818,8 @@ impl Editor { .diagnostic_style .clone(), }) - }, - )) + })) + .render() } }), disposition: BlockDisposition::Below, diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rs index 5cdedd1de7..1ddc5ce771 100644 --- a/crates/editor2/src/element.rs +++ b/crates/editor2/src/element.rs @@ -2253,11 +2253,7 @@ impl LineWithInvisibles { if !line_chunk.is_empty() && !line_exceeded_max_len { let text_style = if let Some(style) = highlighted_chunk.style { - text_style - .clone() - .highlight(style) - .map(Cow::Owned) - .unwrap_or_else(|_| Cow::Borrowed(text_style)) + Cow::Owned(text_style.clone().highlight(style)) } else { Cow::Borrowed(text_style) }; diff --git a/crates/gpui2/src/style.rs b/crates/gpui2/src/style.rs index 664cc61f8a..0819ba9255 100644 --- a/crates/gpui2/src/style.rs +++ b/crates/gpui2/src/style.rs @@ -157,7 +157,7 @@ impl Default for TextStyle { } impl TextStyle { - pub fn highlight(mut self, style: HighlightStyle) -> Result { + pub fn highlight(mut self, style: HighlightStyle) -> Self { if let Some(weight) = style.font_weight { self.font_weight = weight; } @@ -177,7 +177,7 @@ impl TextStyle { self.underline = Some(underline); } - Ok(self) + self } pub fn font(&self) -> Font {