diff options
| author | Laurenz <laurmaedje@gmail.com> | 2024-06-16 09:48:03 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-16 07:48:03 +0000 |
| commit | f25308d1ebd6554d35d512584ca4c3034f230240 (patch) | |
| tree | f49ee99d588d25196eddfff3cca437b4a9c1d716 | |
| parent | 1110b935646fb4174cfce020613378ca7a7e8300 (diff) | |
Tight lists only attach to preceding paragraphs, not blocks anymore (#4396)
| -rw-r--r-- | crates/typst/src/layout/spacing.rs | 5 | ||||
| -rw-r--r-- | crates/typst/src/realize/mod.rs | 10 | ||||
| -rw-r--r-- | tests/ref/issue-1850-list-attach-spacing.png | bin | 0 -> 884 bytes | |||
| -rw-r--r-- | tests/ref/issue-grid-base-auto-row-list.png | bin | 225 -> 234 bytes | |||
| -rw-r--r-- | tests/ref/list-mix.png | bin | 968 -> 1020 bytes | |||
| -rw-r--r-- | tests/ref/par-first-line-indent.png | bin | 11026 -> 10996 bytes | |||
| -rw-r--r-- | tests/ref/set-instantiation-site-markup.png | bin | 1084 -> 1127 bytes | |||
| -rw-r--r-- | tests/suite/model/list.typ | 20 |
8 files changed, 28 insertions, 7 deletions
diff --git a/crates/typst/src/layout/spacing.rs b/crates/typst/src/layout/spacing.rs index 5c02a0cf..571cc870 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 005c399b..824ad3b1 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::<ParbreakElem>() { - self.1 = true; return true; } - let last_was_parbreak = self.1; - self.1 = false; - if let Some(elem) = content.to_packed::<VElem>() { - 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 Binary files differnew file mode 100644 index 00000000..45faa56c --- /dev/null +++ b/tests/ref/issue-1850-list-attach-spacing.png diff --git a/tests/ref/issue-grid-base-auto-row-list.png b/tests/ref/issue-grid-base-auto-row-list.png Binary files differindex 8da3adf5..5033e71d 100644 --- a/tests/ref/issue-grid-base-auto-row-list.png +++ b/tests/ref/issue-grid-base-auto-row-list.png diff --git a/tests/ref/list-mix.png b/tests/ref/list-mix.png Binary files differindex 0f2b03cf..2c263c02 100644 --- a/tests/ref/list-mix.png +++ b/tests/ref/list-mix.png diff --git a/tests/ref/par-first-line-indent.png b/tests/ref/par-first-line-indent.png Binary files differindex e6d7ed76..95027222 100644 --- a/tests/ref/par-first-line-indent.png +++ b/tests/ref/par-first-line-indent.png diff --git a/tests/ref/set-instantiation-site-markup.png b/tests/ref/set-instantiation-site-markup.png Binary files differindex 180444b9..95193e5c 100644 --- a/tests/ref/set-instantiation-site-markup.png +++ b/tests/ref/set-instantiation-site-markup.png diff --git a/tests/suite/model/list.typ b/tests/suite/model/list.typ index 4d3f402d..f9275517 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]) +} |
