fix(style): ensure nested style variables are processed during formatting (#5120)

fix: ensure nested style variables are processed during formatting
This commit is contained in:
Andrew Pantuso 2023-04-24 10:03:04 -04:00 committed by GitHub
parent 43651af4b9
commit e5cec9ea50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View file

@ -91,6 +91,7 @@ impl<'a> StyleVariableHolder<Cow<'a, str>> for Vec<FormatElement<'a>> {
self.iter().fold(BTreeSet::new(), |mut acc, el| match el {
FormatElement::TextGroup(textgroup) => {
acc.extend(textgroup.style.get_style_variables());
acc.extend(textgroup.format.get_style_variables());
acc
}
FormatElement::Conditional(format) => {

View file

@ -569,6 +569,30 @@ mod tests {
match_next!(result_iter, "inner", inner_style);
}
#[test]
fn test_style_variable_nested() {
const STYLE_VAR_NAME: &str = "style";
let format_string = format!("[[text](${STYLE_VAR_NAME})](blue)");
let inner_style = Some(Color::Red.bold());
let formatter = StringFormatter::new(&format_string)
.unwrap()
.map_style(|variable| match variable {
STYLE_VAR_NAME => Some(Ok("red bold".to_owned())),
_ => None,
});
assert_eq!(
BTreeSet::from([STYLE_VAR_NAME.into()]),
formatter.get_style_variables()
);
let result = formatter.parse(None, None).unwrap();
let mut result_iter = result.iter();
match_next!(result_iter, "text", inner_style);
}
#[test]
fn test_styled_variable_as_text() {
const FORMAT_STR: &str = "[$var](red bold)";