diff --git a/crates/engine/src/cmd/addons/typetools/numbers.rs b/crates/engine/src/cmd/addons/typetools/numbers.rs index 4059f1b8e2..2db74afbfb 100644 --- a/crates/engine/src/cmd/addons/typetools/numbers.rs +++ b/crates/engine/src/cmd/addons/typetools/numbers.rs @@ -309,10 +309,10 @@ pub(crate) fn replaced(text: &str, changes: &[Edit]) -> String { /// paragraphs, style runs and ruby that replacing each range by itself with /// [`edit::replace_range`] would give, in one pass over each. pub(crate) fn apply(t: &mut TextObject, changes: &[Edit]) { - let text = t.plain_text(); - let newline = |(a, b, n): &Edit| n.contains('\n') || text.get(*a..*b).is_none_or(|s| s.contains('\n')); - let annotated = !t.ruby.is_empty() || t.runs.iter().any(|r| r.inline.is_some()); - if changes.len() < 2 || annotated || changes.iter().any(newline) { + if changes.len() < 2 || !t.ruby.is_empty() || t.runs.iter().any(|r| r.inline.is_some()) || { + let text = t.plain_text(); + changes.iter().any(|(a, b, n)| n.contains('\n') || text.get(*a..*b).is_none_or(|s| s.contains('\n'))) + } { // One change (a whole text), one that adds or removes paragraphs, or text with ruby or // inline art, whose spans each replacement moves or drops in turn. for (a, b, n) in changes { @@ -371,7 +371,7 @@ fn replace_runs(runs: &mut Vec, changes: &[Edit]) { /// style is copied once for each change of style rather than once for each number. fn push(out: &mut Vec, text: &str, style: &CharStyle) { match out.last_mut() { - Some(last) if last.inline.is_none() && last.style == *style => last.text.push_str(text), + Some(last) if last.style == *style && last.inline.is_none() && style.glyph_alternate.is_none() => last.text.push_str(text), _ => out.push(TextRun { text: text.to_string(), style: style.clone(), inline: None }), } } diff --git a/crates/engine/src/cmd/addons/typetools/numbers/tests.rs b/crates/engine/src/cmd/addons/typetools/numbers/tests.rs index b4dae1c81e..862cffa28c 100644 --- a/crates/engine/src/cmd/addons/typetools/numbers/tests.rs +++ b/crates/engine/src/cmd/addons/typetools/numbers/tests.rs @@ -378,6 +378,7 @@ fn numbers_made_in_one_pass_keep_the_styles_and_ruby_of_one_at_a_time() { (vec![("a12 b", 10.0, None), ("34 c5", 12.0, Some('3')), ("6 -7.8 9", 14.0, None)], vec![(1, 3), (0, 6), (7, 12), (12, 14), (16, 18)]), (vec![("1", 10.0, Some('1')), ("2", 11.0, Some('2')), (" x ", 12.0, None), ("333", 13.0, None)], vec![(0, 2), (2, 4), (5, 8)]), (vec![("no 1, 2 or 3", 10.0, None), ("", 11.0, None), ("44", 12.0, Some('4'))], vec![(3, 4), (4, 9), (13, 14)]), + (vec![("a", 10.0, Some('a')), ("a", 10.0, Some('a')), (" 12 34", 10.0, None)], vec![(3, 5), (6, 8)]), ]; for (runs, spans) in cases { let mut t = base.clone();