diff --git a/crates/typst-layout/src/inline/line.rs b/crates/typst-layout/src/inline/line.rs index 7fcc344f7..cf788b15b 100644 --- a/crates/typst-layout/src/inline/line.rs +++ b/crates/typst-layout/src/inline/line.rs @@ -271,10 +271,10 @@ fn collect_range<'a>( items: &mut Items<'a>, fallback: &mut Option>, ) { - for run in p.slice(range.clone()) { + for (idx, run) in p.slice(range.clone()).enumerate() { // All non-text items are just kept, they can't be split. let Item::Text(shaped) = &run.item else { - items.push(&run.item, run.idx); + items.push(&run.item, idx); continue; }; let subrange = &run.range; @@ -295,10 +295,10 @@ fn collect_range<'a>( } else if split { // When the item is split in half, reshape it. let reshaped = shaped.reshape(engine, sliced); - items.push(Item::Text(reshaped), run.idx); + items.push(Item::Text(reshaped), idx); } else { // When the item is fully contained, just keep it. - items.push(&run.item, run.idx); + items.push(&run.item, idx); } } } diff --git a/crates/typst-layout/src/inline/prepare.rs b/crates/typst-layout/src/inline/prepare.rs index aec90c501..45585496b 100644 --- a/crates/typst-layout/src/inline/prepare.rs +++ b/crates/typst-layout/src/inline/prepare.rs @@ -7,7 +7,6 @@ use super::*; pub struct Run<'a> { pub item: Item<'a>, pub range: Range, - pub idx: usize, } /// A representation in which children are already layouted and text is already @@ -80,7 +79,6 @@ pub fn prepare<'a>( let mut cursor = 0; let mut items = Vec::with_capacity(segments.len()); - let mut next_idx = 0; // Shape the text to finalize the items. for segment in segments { @@ -90,19 +88,10 @@ pub fn prepare<'a>( match segment { Segment::Text(_, styles) => { - shape_range( - &mut items, - engine, - text, - &bidi, - range, - styles, - &mut next_idx, - ); + shape_range(&mut items, engine, text, &bidi, range, styles); } Segment::Item(item) => { - items.push(Run { range, item, idx: next_idx }); - next_idx += 1; + items.push(Run { range, item }); } } diff --git a/crates/typst-layout/src/inline/shaping.rs b/crates/typst-layout/src/inline/shaping.rs index 78c5789a0..3f8bf140e 100644 --- a/crates/typst-layout/src/inline/shaping.rs +++ b/crates/typst-layout/src/inline/shaping.rs @@ -599,7 +599,6 @@ pub fn shape_range<'a>( bidi: &BidiInfo<'a>, range: Range, styles: StyleChain<'a>, - next_idx: &mut usize, ) { let script = TextElem::script_in(styles); let lang = TextElem::lang_in(styles); @@ -608,8 +607,7 @@ pub fn shape_range<'a>( let dir = if level.is_ltr() { Dir::LTR } else { Dir::RTL }; let shaped = shape(engine, range.start, &text[range.clone()], styles, dir, lang, region); - items.push(Run { range, item: Item::Text(shaped), idx: *next_idx }); - *next_idx += 1; + items.push(Run { range, item: Item::Text(shaped) }); }; let mut prev_level = BidiLevel::ltr();