summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/typst/src/model/terms.rs34
-rw-r--r--tests/ref/bugs/1050-terms-indent.pngbin0 -> 22472 bytes
-rw-r--r--tests/ref/layout/terms.pngbin17876 -> 20057 bytes
-rw-r--r--tests/typ/bugs/1050-terms-indent.typ11
-rw-r--r--tests/typ/layout/terms.typ8
5 files changed, 42 insertions, 11 deletions
diff --git a/crates/typst/src/model/terms.rs b/crates/typst/src/model/terms.rs
index 44451be1..983012bd 100644
--- a/crates/typst/src/model/terms.rs
+++ b/crates/typst/src/model/terms.rs
@@ -4,9 +4,11 @@ use crate::foundations::{
cast, elem, scope, Array, Content, NativeElement, Packed, Smart, StyleChain,
};
use crate::layout::{
- BlockElem, Em, Fragment, HElem, LayoutMultiple, Length, Regions, Spacing, VElem,
+ BlockElem, Dir, Em, Fragment, HElem, LayoutMultiple, Length, Regions, Sides, Spacing,
+ StackChild, StackElem,
};
use crate::model::ParElem;
+use crate::text::TextElem;
use crate::util::Numeric;
/// A list of terms and their descriptions.
@@ -125,21 +127,31 @@ impl LayoutMultiple for Packed<TermsElem> {
.unwrap_or_else(|| *BlockElem::below_in(styles).amount())
};
- let mut seq = vec![];
- for (i, child) in self.children().iter().enumerate() {
- if i > 0 {
- seq.push(VElem::new(gutter).with_weakness(1).pack());
- }
- if !indent.is_zero() {
- seq.push(HElem::new(indent.into()).pack());
- }
+ let pad = hanging_indent + indent;
+ let unpad = (!hanging_indent.is_zero())
+ .then(|| HElem::new((-hanging_indent).into()).pack());
+
+ let mut children = vec![];
+ for child in self.children().iter() {
+ let mut seq = vec![];
+ seq.extend(unpad.clone());
seq.push(child.term().clone().strong());
seq.push((*separator).clone());
seq.push(child.description().clone());
+ children.push(StackChild::Block(Content::sequence(seq)));
+ }
+
+ let mut padding = Sides::default();
+ if TextElem::dir_in(styles) == Dir::LTR {
+ padding.left = pad.into();
+ } else {
+ padding.right = pad.into();
}
- Content::sequence(seq)
- .styled(ParElem::set_hanging_indent(hanging_indent + indent))
+ StackElem::new(children)
+ .with_spacing(Some(gutter))
+ .pack()
+ .padded(padding)
.layout(engine, styles, regions)
}
}
diff --git a/tests/ref/bugs/1050-terms-indent.png b/tests/ref/bugs/1050-terms-indent.png
new file mode 100644
index 00000000..58a7feae
--- /dev/null
+++ b/tests/ref/bugs/1050-terms-indent.png
Binary files differ
diff --git a/tests/ref/layout/terms.png b/tests/ref/layout/terms.png
index 00531f98..e0cd013a 100644
--- a/tests/ref/layout/terms.png
+++ b/tests/ref/layout/terms.png
Binary files differ
diff --git a/tests/typ/bugs/1050-terms-indent.typ b/tests/typ/bugs/1050-terms-indent.typ
new file mode 100644
index 00000000..82376820
--- /dev/null
+++ b/tests/typ/bugs/1050-terms-indent.typ
@@ -0,0 +1,11 @@
+#set page(width: 200pt)
+#set par(first-line-indent: 0.5cm)
+
+- #lorem(10)
+- #lorem(10)
+
++ #lorem(10)
++ #lorem(10)
+
+/ Term 1: #lorem(10)
+/ Term 2: #lorem(10)
diff --git a/tests/typ/layout/terms.typ b/tests/typ/layout/terms.typ
index fa94ae12..178aa98b 100644
--- a/tests/typ/layout/terms.typ
+++ b/tests/typ/layout/terms.typ
@@ -22,6 +22,8 @@
An important energy source
for vegetarians.
+ And healthy!
+
---
// Test style change.
#set text(8pt)
@@ -31,6 +33,12 @@
/ Second list: #lorem(5)
---
+// Test RTL.
+#set text(8pt, dir: rtl)
+
+/ פרי: דבר טעים, אכיל. ומקור אנרגיה חשוב לצמחונים.
+
+---
// Test grid like show rule.
#show terms: it => table(
columns: 2,