diff --git a/crates/typst/src/introspection/metadata.rs b/crates/typst/src/introspection/metadata.rs index 287bef678..2d6d8953f 100644 --- a/crates/typst/src/introspection/metadata.rs +++ b/crates/typst/src/introspection/metadata.rs @@ -37,6 +37,8 @@ impl Show for Packed { } } +// TODO: Metadata shows as empty content, so this behaviour is unnecessary. It +// can be removed once 0.11 has landed. impl Behave for Packed { fn behaviour(&self) -> Behaviour { Behaviour::Invisible diff --git a/crates/typst/src/layout/spacing.rs b/crates/typst/src/layout/spacing.rs index 7367c1aa1..f3cb765be 100644 --- a/crates/typst/src/layout/spacing.rs +++ b/crates/typst/src/layout/spacing.rs @@ -68,7 +68,7 @@ impl Behave for Packed { } else if self.weak(StyleChain::default()) { Behaviour::Weak(1) } else { - Behaviour::Invisible + Behaviour::Ignorant } } @@ -166,7 +166,7 @@ impl Behave for Packed { } else if self.weakness(StyleChain::default()) > 0 { Behaviour::Weak(self.weakness(StyleChain::default())) } else { - Behaviour::Invisible + Behaviour::Ignorant } } diff --git a/crates/typst/src/realize/behaviour.rs b/crates/typst/src/realize/behaviour.rs index 533185552..ae44a23e6 100644 --- a/crates/typst/src/realize/behaviour.rs +++ b/crates/typst/src/realize/behaviour.rs @@ -16,9 +16,11 @@ pub enum Behaviour { /// An element that destroys adjacent weak elements. Destructive, /// An element that does not interact at all with other elements, having the - /// same effect as if it didn't exist, but has a visual representation. + /// same effect as if it didn't exist, but has layout extent and/or a visual + /// representation. Ignorant, - /// An element that does not have a visual representation. + /// An element that does not have any layout extent or visual + /// representation. Invisible, } diff --git a/crates/typst/src/realize/mod.rs b/crates/typst/src/realize/mod.rs index 5409cc253..69a961b06 100644 --- a/crates/typst/src/realize/mod.rs +++ b/crates/typst/src/realize/mod.rs @@ -416,6 +416,9 @@ struct ParBuilder<'a>(BehavedBuilder<'a>); impl<'a> ParBuilder<'a> { fn accept(&mut self, content: &'a Content, styles: StyleChain<'a>) -> bool { if content.is::() { + // TODO: This could probably just be `self.0.is_empty()` since no + // weak or invisible elements can be at the start of the builder. It + // can be removed once 0.11 has landed. if self.0.has_strong_elements(false) { self.0.push(content, styles); return true; diff --git a/tests/ref/bugs/spacing-behaviour.png b/tests/ref/bugs/spacing-behaviour.png new file mode 100644 index 000000000..08fcfa739 Binary files /dev/null and b/tests/ref/bugs/spacing-behaviour.png differ diff --git a/tests/typ/bugs/spacing-behaviour.typ b/tests/typ/bugs/spacing-behaviour.typ new file mode 100644 index 000000000..a2a30b8ad --- /dev/null +++ b/tests/typ/bugs/spacing-behaviour.typ @@ -0,0 +1,9 @@ +// Test that metadata after spacing does not force a new paragraph. + +--- +#{ + h(1em) + counter(heading).update(4) + [Hello ] + counter(heading).display() +}