From 8441a72f81e3aca769fa0e62dcdea4e88e267166 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 11 Nov 2026 12:44:26 +0000 Subject: [PATCH] address review: reversed run ranges take the scan --- crates/text/src/layout.rs | 6 +++--- crates/text/src/layout/tests.rs | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/text/src/layout.rs b/crates/text/src/layout.rs index 408efa437..acf292889 100644 --- a/crates/text/src/layout.rs +++ b/crates/text/src/layout.rs @@ -628,10 +628,10 @@ fn is_hanging_open(c: char) -> bool { matches!(c, '"' | '\'' | '\u{2018}' | '\u{201c}' | '(' | '\u{ab}') } -/// Whether each run starts at or after the end of the one before it (the runs of a document): -/// the precondition of [`run_at`]'s bisection. +/// Whether no run is reversed and each starts at or after the end of the one before it (the runs +/// of a document): the precondition of [`run_at`]'s bisection. fn runs_ordered(runs: &[(Range, TextStyle)]) -> bool { - runs.windows(2).all(|w| w[0].0.end <= w[1].0.start) + runs.iter().all(|(r, _)| r.start <= r.end) && runs.windows(2).all(|w| w[0].0.end <= w[1].0.start) } /// Style runs with whether they are [`runs_ordered`]. diff --git a/crates/text/src/layout/tests.rs b/crates/text/src/layout/tests.rs index 0ea8e7474..c467cb5f9 100644 --- a/crates/text/src/layout/tests.rs +++ b/crates/text/src/layout/tests.rs @@ -522,5 +522,12 @@ fn run_lookup_by_bisection_matches_the_scan() { assert_eq!(run_at(&overlapping, false, b), scan(&overlapping, b), "{b}"); } assert_eq!(run_at(&overlapping, false, 6), 0); + // A reversed range (20..0) among others is not ordered either, and takes the scan. + #[allow(clippy::reversed_empty_ranges)] + let reversed: Vec<(Range, TextStyle)> = vec![(0..10, st(10.0)), (20..0, st(20.0)), (5..15, st(30.0)), (15..20, st(40.0))]; + assert!(!runs_ordered(&reversed)); + for b in 0..30 { + assert_eq!(run_at(&reversed, runs_ordered(&reversed), b), scan(&reversed, b), "{b}"); + } assert_eq!(run_at(&[], true, 5), 0); }