Avoid adding unnecessary spans when syntax highlighting

This commit is contained in:
Héctor Ramón Jiménez 2023-09-17 23:15:38 +02:00
parent 790c0dabcf
commit 86d396cf8b
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 14 additions and 12 deletions

View file

@ -154,7 +154,7 @@ winit = { git = "https://github.com/iced-rs/winit.git", rev = "c52db2045d0a2f1b8
[patch.crates-io.cosmic-text]
git = "https://github.com/hecrj/cosmic-text.git"
rev = "cb83458e7d0b84ef37c5beb72dda5046d7d343a6"
branch = "editor-fixes"
[patch.crates-io.rangemap]
git = "https://github.com/hecrj/rangemap.git"

View file

@ -569,17 +569,19 @@ impl editor::Editor for Editor {
for (range, highlight) in highlighter.highlight_line(line.text()) {
let format = format_highlight(&highlight);
list.add_span(
range,
cosmic_text::Attrs {
color_opt: format.color.map(text::to_color),
..if let Some(font) = format.font {
text::to_attributes(font)
} else {
attributes
}
},
);
if format.color.is_some() || format.font.is_some() {
list.add_span(
range,
cosmic_text::Attrs {
color_opt: format.color.map(text::to_color),
..if let Some(font) = format.font {
text::to_attributes(font)
} else {
attributes
}
},
);
}
}
let _ = line.set_attrs_list(list);