Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ fn reorder_levels<'a, T: TextSource<'a> + ?Sized>(
let mut reset_from: Option<usize> = Some(0);
let mut reset_to: Option<usize> = None;
let mut prev_level = para_level;
for (i, c) in line_text.char_indices() {
for ((i, c), (_, length)) in line_text.char_indices().zip(line_text.indices_lengths()) {
match line_classes[i] {
// Segment separator, Paragraph separator
B | S => {
Expand All @@ -1177,7 +1177,9 @@ fn reorder_levels<'a, T: TextSource<'a> + ?Sized>(
reset_from = Some(i);
}
// also set the level to previous
line_levels[i] = prev_level;
for level in &mut line_levels[i..i + length] {
*level = prev_level;
}
}
_ => {
reset_from = None;
Expand Down Expand Up @@ -2039,6 +2041,22 @@ mod tests {
.collect()
}

#[test]
#[cfg(feature = "hardcoded-data")]
fn test_reordered_levels_range() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: link to the issue in a comment?

// |---------------|
let s = "\u{202a}A\u{202c}\u{202a}A\u{202c}";
let range = 4..11;
assert!(s.get(range.clone()).is_some());

let bidi = BidiInfo::new(s, None);
let (_, runs) = bidi.visual_runs(&bidi.paragraphs[0], range);

for run in runs {
let _ = &s[run]; // should be valid slice of s
}
}

#[test]
#[cfg(feature = "hardcoded-data")]
fn test_reordered_levels() {
Expand Down