diff options
| author | Laurenz <laurmaedje@gmail.com> | 2024-02-01 14:30:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-01 13:30:17 +0000 |
| commit | 7d33436e55f8b1aec06d136ebe095dd86bf23e57 (patch) | |
| tree | 2c7b0673ef7a1992c03ef0b3aad4c25a29490400 /crates/typst-macros | |
| parent | 426445edfc8d32d9ff8fcb79cda5b7765209f567 (diff) | |
Fix show-set semantics (#3311)
Diffstat (limited to 'crates/typst-macros')
| -rw-r--r-- | crates/typst-macros/src/elem.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/crates/typst-macros/src/elem.rs b/crates/typst-macros/src/elem.rs index 3a31d3ef..eab359d6 100644 --- a/crates/typst-macros/src/elem.rs +++ b/crates/typst-macros/src/elem.rs @@ -866,6 +866,28 @@ fn create_fields_impl(element: &Elem) -> TokenStream { quote! { Fields::#enum_ident => #expr } }); + // Sets fields from the style chain. + let materializes = visible_non_ghost() + .filter(|field| !field.required && !field.synthesized) + .map(|field| { + let Field { ident, .. } = field; + let value = create_style_chain_access( + field, + false, + if field.ghost { quote!(None) } else { quote!(self.#ident.as_ref()) }, + ); + + if field.fold { + quote! { self.#ident = Some(#value); } + } else { + quote! { + if self.#ident.is_none() { + self.#ident = Some(#value); + } + } + } + }); + // Creation of the `fields` dictionary for inherent fields. let field_inserts = visible_non_ghost().map(|field| { let Field { ident, name, .. } = field; @@ -917,6 +939,10 @@ fn create_fields_impl(element: &Elem) -> TokenStream { } } + fn materialize(&mut self, styles: #foundations::StyleChain) { + #(#materializes)* + } + fn fields(&self) -> #foundations::Dict { let mut fields = #foundations::Dict::new(); #(#field_inserts)* |
