fix new tag preset init

This commit is contained in:
yggverse 2024-12-03 03:14:40 +02:00
parent f832ff6ad0
commit 114a555d03

View File

@ -33,7 +33,7 @@ impl Syntax {
alt: Option<&String>, alt: Option<&String>,
) -> Result<Vec<(TextTag, String)>, Error> { ) -> Result<Vec<(TextTag, String)>, Error> {
if let Some(name) = alt { if let Some(name) = alt {
if let Some(reference) = self.syntax_set.find_syntax_by_extension("rs") { if let Some(reference) = self.syntax_set.find_syntax_by_extension(name) {
return self.syntect_buffer(source_code, source_tag, reference); return self.syntect_buffer(source_code, source_tag, reference);
} }
} }
@ -49,9 +49,8 @@ impl Syntax {
// Init new line buffer // Init new line buffer
let mut buffer = Vec::new(); let mut buffer = Vec::new();
// Create new tag from source preset // Create new tag preset from source
let mut tag = TextTag::new(None); let tag = new_text_tag_from(source_tag);
// @TODO copy preset tag.clone_from(source_tag);
// Append // Append
buffer.push((tag, source.to_string())); buffer.push((tag, source.to_string()));
@ -73,9 +72,8 @@ impl Syntax {
// Build tags // Build tags
for (style, entity) in ranges { for (style, entity) in ranges {
// Create new tag from source preset // Create new tag preset from source
let mut tag = TextTag::new(None); let tag = new_text_tag_from(source_tag);
// @TODO copy preset tag.clone_from(source_tag);
// Tuneup using syntect conversion // Tuneup using syntect conversion
// tag.set_background_rgba(Some(&color_to_rgba(style.background))); // tag.set_background_rgba(Some(&color_to_rgba(style.background)));
@ -122,3 +120,13 @@ fn font_style_to_underline(font_style: FontStyle) -> Underline {
_ => Underline::None, _ => Underline::None,
} }
} }
fn new_text_tag_from(source_tag: &TextTag) -> TextTag {
TextTag::builder()
.foreground_rgba(&source_tag.foreground_rgba().unwrap())
.family(source_tag.family().unwrap())
.left_margin(source_tag.left_margin())
.scale(source_tag.scale())
.wrap_mode(source_tag.wrap_mode())
.build()
}