summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Pantuso <ajpantuso@gmail.com>2023-04-24 10:03:04 -0400
committerGitHub <noreply@github.com>2023-04-24 16:03:04 +0200
commite5cec9ea50963a45bb1c209abc747ee1983dcabd (patch)
tree13168e78d1c9c5551b736bf69ce2438bb41165be
parent43651af4b9e269aaa741c34238e35c8acdad8155 (diff)
fix(style): ensure nested style variables are processed during formatting (#5120)
fix: ensure nested style variables are processed during formatting
-rw-r--r--src/formatter/model.rs1
-rw-r--r--src/formatter/string_formatter.rs24
2 files changed, 25 insertions, 0 deletions
diff --git a/src/formatter/model.rs b/src/formatter/model.rs
index 291bf80be..2db307750 100644
--- a/src/formatter/model.rs
+++ b/src/formatter/model.rs
@@ -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) => {
diff --git a/src/formatter/string_formatter.rs b/src/formatter/string_formatter.rs
index 229407d34..249048949 100644
--- a/src/formatter/string_formatter.rs
+++ b/src/formatter/string_formatter.rs
@@ -570,6 +570,30 @@ mod tests {
}
#[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)";
let var_style = Some(Color::Red.bold());