Remove idx field from Run

This commit is contained in:
+merlan #flirora 2025-02-18 16:00:14 -05:00
parent 7e69ee0942
commit 2fd8046405
3 changed files with 7 additions and 20 deletions

View File

@ -271,10 +271,10 @@ fn collect_range<'a>(
items: &mut Items<'a>, items: &mut Items<'a>,
fallback: &mut Option<ItemEntry<'a>>, fallback: &mut Option<ItemEntry<'a>>,
) { ) {
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. // All non-text items are just kept, they can't be split.
let Item::Text(shaped) = &run.item else { let Item::Text(shaped) = &run.item else {
items.push(&run.item, run.idx); items.push(&run.item, idx);
continue; continue;
}; };
let subrange = &run.range; let subrange = &run.range;
@ -295,10 +295,10 @@ fn collect_range<'a>(
} else if split { } else if split {
// When the item is split in half, reshape it. // When the item is split in half, reshape it.
let reshaped = shaped.reshape(engine, sliced); let reshaped = shaped.reshape(engine, sliced);
items.push(Item::Text(reshaped), run.idx); items.push(Item::Text(reshaped), idx);
} else { } else {
// When the item is fully contained, just keep it. // When the item is fully contained, just keep it.
items.push(&run.item, run.idx); items.push(&run.item, idx);
} }
} }
} }

View File

@ -7,7 +7,6 @@ use super::*;
pub struct Run<'a> { pub struct Run<'a> {
pub item: Item<'a>, pub item: Item<'a>,
pub range: Range, pub range: Range,
pub idx: usize,
} }
/// A representation in which children are already layouted and text is already /// 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 cursor = 0;
let mut items = Vec::with_capacity(segments.len()); let mut items = Vec::with_capacity(segments.len());
let mut next_idx = 0;
// Shape the text to finalize the items. // Shape the text to finalize the items.
for segment in segments { for segment in segments {
@ -90,19 +88,10 @@ pub fn prepare<'a>(
match segment { match segment {
Segment::Text(_, styles) => { Segment::Text(_, styles) => {
shape_range( shape_range(&mut items, engine, text, &bidi, range, styles);
&mut items,
engine,
text,
&bidi,
range,
styles,
&mut next_idx,
);
} }
Segment::Item(item) => { Segment::Item(item) => {
items.push(Run { range, item, idx: next_idx }); items.push(Run { range, item });
next_idx += 1;
} }
} }

View File

@ -599,7 +599,6 @@ pub fn shape_range<'a>(
bidi: &BidiInfo<'a>, bidi: &BidiInfo<'a>,
range: Range, range: Range,
styles: StyleChain<'a>, styles: StyleChain<'a>,
next_idx: &mut usize,
) { ) {
let script = TextElem::script_in(styles); let script = TextElem::script_in(styles);
let lang = TextElem::lang_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 dir = if level.is_ltr() { Dir::LTR } else { Dir::RTL };
let shaped = let shaped =
shape(engine, range.start, &text[range.clone()], styles, dir, lang, region); shape(engine, range.start, &text[range.clone()], styles, dir, lang, region);
items.push(Run { range, item: Item::Text(shaped), idx: *next_idx }); items.push(Run { range, item: Item::Text(shaped) });
*next_idx += 1;
}; };
let mut prev_level = BidiLevel::ltr(); let mut prev_level = BidiLevel::ltr();