diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-03-29 14:27:17 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-03-30 14:31:46 +0200 |
| commit | c393eccd36c7bc69ba340c9fcd2efd916a7b9e43 (patch) | |
| tree | 9a1e59538aef44a52d59be79dd60dbf176b3eb61 /src/layout | |
| parent | 652986fd58db96036c31e397cc8651135845d06e (diff) | |
Fix space/newline trimming 🐞
Co-Authored-By: Martin <mhaug@live.de>
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/par.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/layout/par.rs b/src/layout/par.rs index 902ffafa..6a226fb4 100644 --- a/src/layout/par.rs +++ b/src/layout/par.rs @@ -5,6 +5,7 @@ use xi_unicode::LineBreakIterator; use super::*; use crate::exec::FontProps; +use crate::parse::is_newline; /// A node that arranges its children into a paragraph. #[derive(Debug, Clone, PartialEq)] @@ -123,8 +124,15 @@ impl ParLayouter { let mut iter = LineBreakIterator::new(&node.text).peekable(); while let Some(&(pos, mandatory)) = iter.peek() { - let part = &node.text[start .. pos].trim_end(); - let frame = shape(part, &mut ctx.env.fonts, &node.props); + let line = &node.text[start .. pos]; + + // Remove trailing newline and spacing at the end of lines. + let mut line = line.trim_end_matches(is_newline); + if pos != node.text.len() { + line = line.trim_end(); + } + + let frame = shape(line, &mut ctx.env.fonts, &node.props); if self.usable().fits(frame.size) { // Still fits into the line. |
