diff --git a/crates/typst-library/src/layout/par.rs b/crates/typst-library/src/layout/par.rs index 9e5d4a97e..235791052 100644 --- a/crates/typst-library/src/layout/par.rs +++ b/crates/typst-library/src/layout/par.rs @@ -929,9 +929,22 @@ fn linebreak_optimized<'a>(vt: &Vt, p: &'a Preparation<'a>, width: Abs) -> Vec = None; // Find the optimal predecessor. - for (i, pred) in table.iter_mut().enumerate().skip(active) { + for (i, pred) in table.iter().enumerate().skip(active) { // Layout the line. let start = pred.line.end; + + // Fix for https://github.com/unicode-org/icu4x/issues/3811 + if i > 0 { + if let Some(s_pred) = table.get(i + 1) { + let next_start = s_pred.line.end; + if !p.bidi.text[start..next_start] + .contains(|c: char| !c.is_whitespace()) + { + continue; + } + } + } + let attempt = line(vt, p, start..end, mandatory, hyphen); // Determine how much the line's spaces would need to be stretched @@ -996,7 +1009,7 @@ fn linebreak_optimized<'a>(vt: &Vt, p: &'a Preparation<'a>, width: Abs) -> Vec