summaryrefslogtreecommitdiff
path: root/library/src/layout/flow.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-17 12:40:58 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-17 12:46:26 +0100
commitcabd0908e230e451bd9f1394390f8c5deb17182e (patch)
tree665fe796b8487a0913fbc35aeed527c20050eca3 /library/src/layout/flow.rs
parentbf59c08a0a601eeac4354c505cab15e65601c8e8 (diff)
Handle paragraph indent at a later stage
Diffstat (limited to 'library/src/layout/flow.rs')
-rw-r--r--library/src/layout/flow.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/library/src/layout/flow.rs b/library/src/layout/flow.rs
index b05146c9..f47a8f42 100644
--- a/library/src/layout/flow.rs
+++ b/library/src/layout/flow.rs
@@ -1,3 +1,5 @@
+use typst::model::{Property, StyleEntry};
+
use super::{AlignNode, ColbreakNode, PlaceNode, Spacing, VNode};
use crate::prelude::*;
use crate::text::ParNode;
@@ -58,6 +60,8 @@ struct FlowLayouter {
used: Size,
/// The sum of fractions in the current region.
fr: Fr,
+ /// Whether the last block was a paragraph.
+ last_block_was_par: bool,
/// Spacing and layouted blocks.
items: Vec<FlowItem>,
/// Finished frames for previous regions.
@@ -92,6 +96,7 @@ impl FlowLayouter {
full,
used: Size::zero(),
fr: Fr::zero(),
+ last_block_was_par: false,
items: vec![],
finished: vec![],
}
@@ -150,8 +155,18 @@ impl FlowLayouter {
.unwrap_or(Align::Top),
);
+ // Disable paragraph indent if this is not a consecutive paragraph.
+ let reset;
+ let is_par = block.is::<ParNode>();
+ let mut chained = styles;
+ if !self.last_block_was_par && is_par && !styles.get(ParNode::INDENT).is_zero() {
+ let property = Property::new(ParNode::INDENT, Length::zero());
+ reset = StyleEntry::Property(property);
+ chained = reset.chain(&styles);
+ }
+
// Layout the block itself.
- let frames = block.layout_block(world, &self.regions, styles)?;
+ let frames = block.layout_block(world, &self.regions, chained)?;
let len = frames.len();
for (i, frame) in frames.into_iter().enumerate() {
// Grow our size, shrink the region and save the frame for later.
@@ -166,6 +181,8 @@ impl FlowLayouter {
}
}
+ self.last_block_was_par = is_par;
+
Ok(())
}