diff options
| author | Sébastien d'Herbais de Thun <sebastien.d.herbais@gmail.com> | 2024-11-26 21:51:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-26 20:51:46 +0000 |
| commit | 85d3a49a1a0bd50556b8b724a15aa29b074a2db7 (patch) | |
| tree | bbce57ce9e782d28ea10e148027aa25198958384 /crates/typst-library | |
| parent | 8fe8b2a23940f76077aa36eda305febd22e7cadc (diff) | |
Added warning when explicit return in code (not markup) discards joined content (#5413)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'crates/typst-library')
| -rw-r--r-- | crates/typst-library/src/foundations/content.rs | 2 | ||||
| -rw-r--r-- | crates/typst-library/src/introspection/counter.rs | 5 | ||||
| -rw-r--r-- | crates/typst-library/src/introspection/state.rs | 5 | ||||
| -rw-r--r-- | crates/typst-library/src/model/figure.rs | 4 |
4 files changed, 13 insertions, 3 deletions
diff --git a/crates/typst-library/src/foundations/content.rs b/crates/typst-library/src/foundations/content.rs index a274b8bf..69103e08 100644 --- a/crates/typst-library/src/foundations/content.rs +++ b/crates/typst-library/src/foundations/content.rs @@ -426,7 +426,7 @@ impl Content { /// selector. /// /// Elements produced in `show` rules will not be included in the results. - pub fn query_first(&self, selector: Selector) -> Option<Content> { + pub fn query_first(&self, selector: &Selector) -> Option<Content> { let mut result = None; self.traverse(&mut |element| { if result.is_none() && selector.matches(&element, None) { diff --git a/crates/typst-library/src/introspection/counter.rs b/crates/typst-library/src/introspection/counter.rs index 2e7180c6..b884844c 100644 --- a/crates/typst-library/src/introspection/counter.rs +++ b/crates/typst-library/src/introspection/counter.rs @@ -393,6 +393,11 @@ impl Counter { let context = Context::new(Some(location), styles); state.display(engine, context.track(), &numbering) } + + /// Selects all state updates. + pub fn select_any() -> Selector { + CounterUpdateElem::elem().select() + } } #[scope] diff --git a/crates/typst-library/src/introspection/state.rs b/crates/typst-library/src/introspection/state.rs index 62aba5ff..772a4fbf 100644 --- a/crates/typst-library/src/introspection/state.rs +++ b/crates/typst-library/src/introspection/state.rs @@ -261,6 +261,11 @@ impl State { fn selector(&self) -> Selector { select_where!(StateUpdateElem, Key => self.key.clone()) } + + /// Selects all state updates. + pub fn select_any() -> Selector { + StateUpdateElem::elem().select() + } } #[scope] diff --git a/crates/typst-library/src/model/figure.rs b/crates/typst-library/src/model/figure.rs index abdf2a4e..3e2777c1 100644 --- a/crates/typst-library/src/model/figure.rs +++ b/crates/typst-library/src/model/figure.rs @@ -257,7 +257,7 @@ impl Synthesize for Packed<FigureElem> { // Determine the figure's kind. let kind = elem.kind(styles).unwrap_or_else(|| { elem.body() - .query_first(Selector::can::<dyn Figurable>()) + .query_first(&Selector::can::<dyn Figurable>()) .map(|elem| FigureKind::Elem(elem.func())) .unwrap_or_else(|| FigureKind::Elem(ImageElem::elem())) }); @@ -289,7 +289,7 @@ impl Synthesize for Packed<FigureElem> { let descendant = match kind { FigureKind::Elem(func) => elem .body() - .query_first(Selector::Elem(func, None)) + .query_first(&Selector::Elem(func, None)) .map(Cow::Owned), FigureKind::Name(_) => None, }; |
