diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-09-25 23:35:27 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-09-25 23:35:27 +0200 |
| commit | 5594868f8b7a3ca5155804653fc2f2d2fb84a48e (patch) | |
| tree | 5ee923b831417b4ff8ad3f8e1353a90624ea66f8 /src/layout/par.rs | |
| parent | cdb9867e0d3c91c5f1e6a93bb9e34e1824d184f7 (diff) | |
Prevent paragraph from overflowing due to trailing linebreak
Diffstat (limited to 'src/layout/par.rs')
| -rw-r--r-- | src/layout/par.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/layout/par.rs b/src/layout/par.rs index dc2ce0ef..18a701cd 100644 --- a/src/layout/par.rs +++ b/src/layout/par.rs @@ -218,21 +218,25 @@ impl<'a> ParLayouter<'a> { stack.constraints.max.y.set_min(stack.size.h + line.size.h); stack.finish_region(ctx); } + // If the line does not fit horizontally or we have a mandatory // line break (i.e. due to "\n"), we push the line into the // stack. if mandatory || !stack.regions.current.w.fits(line.size.w) { - stack.push(line); start = end; last = None; + stack.push(line); stack.constraints.min.y = Some(stack.size.h); // If there is a trailing line break at the end of the // paragraph, we want to force an empty line. if mandatory && end == self.bidi.text.len() { - stack.push(LineLayout::new(ctx, &self, end .. end)); - stack.constraints.min.y = Some(stack.size.h); + let line = LineLayout::new(ctx, &self, end .. end); + if stack.regions.current.h.fits(line.size.h) { + stack.push(line); + stack.constraints.min.y = Some(stack.size.h); + } } } else { // Otherwise, the line fits both horizontally and vertically |
