Skip to content

Commit

Permalink
Prevent inline boxes from being duplicated when the line ends with an
Browse files Browse the repository at this point in the history
inline box.
  • Loading branch information
nicoburns committed Dec 6, 2024
1 parent 564c981 commit 6d8f0fb
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions parley/src/layout/line/greedy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ fn try_commit_line<B: Brush>(

// Iterate over the items to commit
// println!("\nCOMMIT LINE");
let mut last_item_kind = LayoutItemKind::TextRun;
for (i, item) in items_to_commit.iter().enumerate() {
// println!("i = {} index = {} {:?}", i, item.index, item.kind);

Expand All @@ -745,6 +746,8 @@ fn try_commit_line<B: Brush>(
cluster_range: 0..0,
text_range: 0..0,
});

last_item_kind = item.kind;
}
LayoutItemKind::TextRun => {
let run_data = &layout.data.runs[item.index];
Expand All @@ -768,6 +771,8 @@ fn try_commit_line<B: Brush>(
continue;
}

last_item_kind = item.kind;

// Push run to line
let run = Run::new(layout, 0, 0, run_data, None);
let text_range = if run_data.cluster_range.is_empty() {
Expand Down Expand Up @@ -825,10 +830,21 @@ fn try_commit_line<B: Brush>(
});

// Reset state for the new line
state.num_spaces = 0;
state.clusters.start = state.clusters.end;
state.clusters.end += 1;
state.items.start = state.items.end.saturating_sub(1);
state.num_spaces = 0;

state.items.start = match last_item_kind {
// For text runs, the first item of line N+1 needs to be the SAME as
// the last item for line N. This is because the item (if it a text run
// may be split across the two lines with some clusters in line N and some
// in line N+1). The item is later filtered out (see `continue` in loop above)
// if there are not actually any clusters in line N+1.
LayoutItemKind::TextRun => state.items.end.saturating_sub(1),
// Inline boxes cannot be spread across multiple lines, so we should set
// the first item of line N+1 to be the item AFTER the last item in line N.
LayoutItemKind::InlineBox => state.items.end,
};

true
}
Expand Down

0 comments on commit 6d8f0fb

Please sign in to comment.