diff options
| author | Laurenz <laurmaedje@gmail.com> | 2024-03-12 12:32:53 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-12 11:32:53 +0000 |
| commit | 0fef85706451331b00d09dc85a77a812c779ce6c (patch) | |
| tree | 0689d5565d2a2f30134c3233f396a5d4814a28b8 | |
| parent | 1d027ff6d22a2961d5078aa7e1abaa2710a1fb0e (diff) | |
Fix `Behaviour` of spacing (#3634)
| -rw-r--r-- | crates/typst/src/introspection/metadata.rs | 2 | ||||
| -rw-r--r-- | crates/typst/src/layout/spacing.rs | 4 | ||||
| -rw-r--r-- | crates/typst/src/realize/behaviour.rs | 6 | ||||
| -rw-r--r-- | crates/typst/src/realize/mod.rs | 3 | ||||
| -rw-r--r-- | tests/ref/bugs/spacing-behaviour.png | bin | 0 -> 638 bytes | |||
| -rw-r--r-- | tests/typ/bugs/spacing-behaviour.typ | 9 |
6 files changed, 20 insertions, 4 deletions
diff --git a/crates/typst/src/introspection/metadata.rs b/crates/typst/src/introspection/metadata.rs index 287bef67..2d6d8953 100644 --- a/crates/typst/src/introspection/metadata.rs +++ b/crates/typst/src/introspection/metadata.rs @@ -37,6 +37,8 @@ impl Show for Packed<MetadataElem> { } } +// TODO: Metadata shows as empty content, so this behaviour is unnecessary. It +// can be removed once 0.11 has landed. impl Behave for Packed<MetadataElem> { fn behaviour(&self) -> Behaviour { Behaviour::Invisible diff --git a/crates/typst/src/layout/spacing.rs b/crates/typst/src/layout/spacing.rs index 7367c1aa..f3cb765b 100644 --- a/crates/typst/src/layout/spacing.rs +++ b/crates/typst/src/layout/spacing.rs @@ -68,7 +68,7 @@ impl Behave for Packed<HElem> { } else if self.weak(StyleChain::default()) { Behaviour::Weak(1) } else { - Behaviour::Invisible + Behaviour::Ignorant } } @@ -166,7 +166,7 @@ impl Behave for Packed<VElem> { } 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 53318555..ae44a23e 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 5409cc25..69a961b0 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::<MetaElem>() { + // 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 Binary files differnew file mode 100644 index 00000000..08fcfa73 --- /dev/null +++ b/tests/ref/bugs/spacing-behaviour.png diff --git a/tests/typ/bugs/spacing-behaviour.typ b/tests/typ/bugs/spacing-behaviour.typ new file mode 100644 index 00000000..a2a30b8a --- /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() +} |
