From f39a8bc01521d55da5296dccef8fb7dd9d3f6327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20d=27Herbais=20de=20Thun?= Date: Wed, 15 Nov 2023 14:49:29 +0100 Subject: [PATCH] Add span information to realized `ParElem` (#2675) --- crates/typst-library/src/layout/mod.rs | 10 +++++++++- crates/typst-library/src/math/ctx.rs | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/typst-library/src/layout/mod.rs b/crates/typst-library/src/layout/mod.rs index d31f68416..77e62dd31 100644 --- a/crates/typst-library/src/layout/mod.rs +++ b/crates/typst-library/src/layout/mod.rs @@ -637,7 +637,15 @@ impl<'a> ParBuilder<'a> { fn finish(self) -> (Content, StyleChain<'a>) { let (children, shared) = self.0.finish(); - (ParElem::new(children.to_vec()).pack(), shared) + + // Find the first span that isn't detached. + let span = children + .iter() + .map(|(cnt, _)| cnt.span()) + .find(|span| !span.is_detached()) + .unwrap_or_else(Span::detached); + + (ParElem::new(children.to_vec()).spanned(span).pack(), shared) } } diff --git a/crates/typst-library/src/math/ctx.rs b/crates/typst-library/src/math/ctx.rs index 2637921ce..789bd3329 100644 --- a/crates/typst-library/src/math/ctx.rs +++ b/crates/typst-library/src/math/ctx.rs @@ -252,7 +252,9 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> { // because it will be placed somewhere probably not at the left margin // it will overflow. So emulate an `hbox` instead and allow the paragraph // to extend as far as needed. + let span = elem.span(); let frame = ParElem::new(vec![Prehashed::new(elem)]) + .spanned(span) .layout( self.vt, self.outer.chain(&self.local),