From f07e4bcbe1ef871542a4056e6042c710a0a887f7 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sat, 7 Dec 2024 11:18:11 +1300 Subject: [PATCH] Fix trailing whitespace computation A line does not have trailing whitespace if the last item is an inline box. --- parley/src/layout/line/greedy.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/parley/src/layout/line/greedy.rs b/parley/src/layout/line/greedy.rs index 31816def..14bf455f 100644 --- a/parley/src/layout/line/greedy.rs +++ b/parley/src/layout/line/greedy.rs @@ -529,14 +529,10 @@ impl<'a, B: Brush> BreakLines<'a, B> { line.metrics.trailing_whitespace = 0.0; if !line.item_range.is_empty() { // Note: there may not be a "last run" if there are no runs in the line - let last_run = &self - .lines - .line_items - .iter() - .rfind(|item| item.is_text_run()); - if let Some(last_run) = last_run { - if !last_run.cluster_range.is_empty() { - let cluster = &self.layout.data.clusters[last_run.cluster_range.end - 1]; + let last_item = &self.lines.line_items.last(); + if let Some(last_item) = last_item { + if last_item.is_text_run() && !last_item.cluster_range.is_empty() { + let cluster = &self.layout.data.clusters[last_item.cluster_range.end - 1]; if cluster.info.whitespace().is_space_or_nbsp() { line.metrics.trailing_whitespace = cluster.advance; }