Don't return Result from TextStyle::highlight

This commit is contained in:
Antonio Scandurra 2023-11-15 09:10:46 +01:00
parent 48b3a90fbf
commit 1def355d44
4 changed files with 13 additions and 27 deletions

View file

@ -578,12 +578,7 @@ impl DisplaySnapshot {
line.push_str(chunk.chunk); line.push_str(chunk.chunk);
let text_style = if let Some(style) = chunk.style { let text_style = if let Some(style) = chunk.style {
editor_style Cow::Owned(editor_style.text.clone().highlight(style))
.text
.clone()
.highlight(style)
.map(Cow::Owned)
.unwrap_or_else(|_| Cow::Borrowed(&editor_style.text))
} else { } else {
Cow::Borrowed(&editor_style.text) Cow::Borrowed(&editor_style.text)
}; };

View file

@ -7798,20 +7798,15 @@ impl Editor {
render: Arc::new({ render: Arc::new({
let rename_editor = rename_editor.clone(); let rename_editor = rename_editor.clone();
move |cx: &mut BlockContext| { 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)) .and_then(|h| h.style(&cx.editor_style.syntax))
{ {
cx.editor_style text_style = text_style.highlight(highlight_style);
.text }
.clone() div()
.highlight(highlight_style) .pl(cx.anchor_x)
.unwrap_or_else(|_| cx.editor_style.text.clone()) .child(with_view(&rename_editor, |_, _| {
} else {
cx.editor_style.text.clone()
};
div().pl(cx.anchor_x).child(with_view(
&rename_editor,
|_, _| {
EditorElement::new(EditorStyle { EditorElement::new(EditorStyle {
background: cx.theme().system().transparent, background: cx.theme().system().transparent,
local_player: cx.editor_style.local_player, local_player: cx.editor_style.local_player,
@ -7823,8 +7818,8 @@ impl Editor {
.diagnostic_style .diagnostic_style
.clone(), .clone(),
}) })
}, }))
)) .render()
} }
}), }),
disposition: BlockDisposition::Below, disposition: BlockDisposition::Below,

View file

@ -2253,11 +2253,7 @@ impl LineWithInvisibles {
if !line_chunk.is_empty() && !line_exceeded_max_len { if !line_chunk.is_empty() && !line_exceeded_max_len {
let text_style = if let Some(style) = highlighted_chunk.style { let text_style = if let Some(style) = highlighted_chunk.style {
text_style Cow::Owned(text_style.clone().highlight(style))
.clone()
.highlight(style)
.map(Cow::Owned)
.unwrap_or_else(|_| Cow::Borrowed(text_style))
} else { } else {
Cow::Borrowed(text_style) Cow::Borrowed(text_style)
}; };

View file

@ -157,7 +157,7 @@ impl Default for TextStyle {
} }
impl TextStyle { impl TextStyle {
pub fn highlight(mut self, style: HighlightStyle) -> Result<Self> { pub fn highlight(mut self, style: HighlightStyle) -> Self {
if let Some(weight) = style.font_weight { if let Some(weight) = style.font_weight {
self.font_weight = weight; self.font_weight = weight;
} }
@ -177,7 +177,7 @@ impl TextStyle {
self.underline = Some(underline); self.underline = Some(underline);
} }
Ok(self) self
} }
pub fn font(&self) -> Font { pub fn font(&self) -> Font {