Fix logical order in bidirectional lines (#6796)

This commit is contained in:
Laurenz 2025-08-21 14:50:16 +02:00 committed by GitHub
parent 880e69b0c8
commit eb93294171
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 6 deletions

View File

@ -271,7 +271,7 @@ fn collect_range<'a>(
items: &mut Items<'a>, items: &mut Items<'a>,
fallback: &mut Option<ItemEntry<'a>>, fallback: &mut Option<ItemEntry<'a>>,
) { ) {
for (idx, (subrange, item)) in p.slice(range.clone()).enumerate() { for (idx, (subrange, item)) in p.slice(range.clone()) {
// 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) = item else { let Item::Text(shaped) = item else {
items.push(item, idx); items.push(item, idx);

View File

@ -34,8 +34,12 @@ impl<'a> Preparation<'a> {
&self.items[idx] &self.items[idx]
} }
/// Iterate over the items that intersect the given `sliced` range. /// Iterate over the items that intersect the given `sliced` range alongside
pub fn slice(&self, sliced: Range) -> impl Iterator<Item = &(Range, Item<'a>)> { /// their indices in `self.items` and their ranges in the paragraph's text.
pub fn slice(
&self,
sliced: Range,
) -> impl Iterator<Item = (usize, &(Range, Item<'a>))> {
// Usually, we don't want empty-range items at the start of the line // Usually, we don't want empty-range items at the start of the line
// (because they will be part of the previous line), but for the first // (because they will be part of the previous line), but for the first
// line, we need to keep them. // line, we need to keep them.
@ -43,7 +47,11 @@ impl<'a> Preparation<'a> {
0 => 0, 0 => 0,
n => self.indices.get(n).copied().unwrap_or(0), n => self.indices.get(n).copied().unwrap_or(0),
}; };
self.items[start..].iter().take_while(move |(range, _)| { self.items
.iter()
.enumerate()
.skip(start)
.take_while(move |(_, (range, _))| {
range.start < sliced.end || range.end <= sliced.end range.start < sliced.end || range.end <= sliced.end
}) })
} }

BIN
tests/ref/counter-rtl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -174,3 +174,12 @@ B
#context test(c.get(), (100000000002,)) #context test(c.get(), (100000000002,))
#c.update(n => n + 2) #c.update(n => n + 2)
#context test(c.get(), (100000000004,)) #context test(c.get(), (100000000004,))
--- counter-rtl ---
#set page(width: auto)
#let c = counter("c")
#let s = context c.display() + c.step()
#let tree = [درخت]
#let line = [A #s B #tree #s #tree #s #tree C #s D #s]
#line \
#line