diff --git a/crates/typst/src/layout/spacing.rs b/crates/typst/src/layout/spacing.rs index 5c02a0cf1..571cc8704 100644 --- a/crates/typst/src/layout/spacing.rs +++ b/crates/typst/src/layout/spacing.rs @@ -126,12 +126,13 @@ pub struct VElem { #[external] pub weak: bool, - /// The element's weakness level, see also [`Behaviour`]. + /// The spacing's weakness level, see also [`Behaviour`]. #[internal] #[parse(args.named("weak")?.map(|v: bool| v as usize))] pub weakness: usize, - /// Whether the element collapses if there is a parbreak in front. + /// Whether the spacing collapses if not immediately preceded by a + /// paragraph. #[internal] #[parse(Some(false))] pub attach: bool, diff --git a/crates/typst/src/realize/mod.rs b/crates/typst/src/realize/mod.rs index 005c399be..824ad3b1a 100644 --- a/crates/typst/src/realize/mod.rs +++ b/crates/typst/src/realize/mod.rs @@ -385,16 +385,15 @@ impl<'a> FlowBuilder<'a> { content: &'a Content, styles: StyleChain<'a>, ) -> bool { + let last_was_par = self.1; + self.1 = false; + if content.is::() { - self.1 = true; return true; } - let last_was_parbreak = self.1; - self.1 = false; - if let Some(elem) = content.to_packed::() { - if !elem.attach(styles) || !last_was_parbreak { + if !elem.attach(styles) || last_was_par { self.0.push(content, styles); } return true; @@ -434,6 +433,7 @@ impl<'a> FlowBuilder<'a> { self.0.push(*par_spacing, styles); self.0.push(content, styles); self.0.push(*par_spacing, styles); + self.1 = true; return true; } diff --git a/tests/ref/issue-1850-list-attach-spacing.png b/tests/ref/issue-1850-list-attach-spacing.png new file mode 100644 index 000000000..45faa56c4 Binary files /dev/null and b/tests/ref/issue-1850-list-attach-spacing.png differ diff --git a/tests/ref/issue-grid-base-auto-row-list.png b/tests/ref/issue-grid-base-auto-row-list.png index 8da3adf5d..5033e71d3 100644 Binary files a/tests/ref/issue-grid-base-auto-row-list.png and b/tests/ref/issue-grid-base-auto-row-list.png differ diff --git a/tests/ref/list-mix.png b/tests/ref/list-mix.png index 0f2b03cf9..2c263c02c 100644 Binary files a/tests/ref/list-mix.png and b/tests/ref/list-mix.png differ diff --git a/tests/ref/par-first-line-indent.png b/tests/ref/par-first-line-indent.png index e6d7ed761..95027222f 100644 Binary files a/tests/ref/par-first-line-indent.png and b/tests/ref/par-first-line-indent.png differ diff --git a/tests/ref/set-instantiation-site-markup.png b/tests/ref/set-instantiation-site-markup.png index 180444b99..95193e5cd 100644 Binary files a/tests/ref/set-instantiation-site-markup.png and b/tests/ref/set-instantiation-site-markup.png differ diff --git a/tests/suite/model/list.typ b/tests/suite/model/list.typ index 4d3f402dc..f92755174 100644 --- a/tests/suite/model/list.typ +++ b/tests/suite/model/list.typ @@ -145,3 +145,23 @@ World --- issue-2530-list-item-panic --- // List item (pre-emptive) #list.item[Hello] + +--- issue-1850-list-attach-spacing --- +// List attachment should only work with paragraphs, not other blocks. +#set page(width: auto) +#let part = box.with(stroke: 1pt, inset: 3pt) +#{ + part[ + $ x $ + - A + ] + part($ x $ + list[A]) + part($ x $ + list[ A ]) + part[ + $ x $ + + - A + ] + part($ x $ + parbreak() + list[A]) + part($ x $ + parbreak() + parbreak() + list[A]) +}