mirror of
https://github.com/typst/typst
synced 2025-08-23 03:04:14 +08:00
Fix logical order in bidirectional lines (#6796)
This commit is contained in:
parent
880e69b0c8
commit
eb93294171
@ -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);
|
||||||
|
@ -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,9 +47,13 @@ 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
|
||||||
range.start < sliced.end || range.end <= sliced.end
|
.iter()
|
||||||
})
|
.enumerate()
|
||||||
|
.skip(start)
|
||||||
|
.take_while(move |(_, (range, _))| {
|
||||||
|
range.start < sliced.end || range.end <= sliced.end
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
tests/ref/counter-rtl.png
Normal file
BIN
tests/ref/counter-rtl.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user