mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Fixes counter stepping behavior (#4631)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
parent
9909f12d4f
commit
211b546e4e
@ -685,14 +685,12 @@ impl CounterState {
|
|||||||
pub fn step(&mut self, level: NonZeroUsize, by: usize) {
|
pub fn step(&mut self, level: NonZeroUsize, by: usize) {
|
||||||
let level = level.get();
|
let level = level.get();
|
||||||
|
|
||||||
if self.0.len() >= level {
|
while self.0.len() < level {
|
||||||
self.0[level - 1] = self.0[level - 1].saturating_add(by);
|
self.0.push(0);
|
||||||
self.0.truncate(level);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while self.0.len() < level {
|
self.0[level - 1] = self.0[level - 1].saturating_add(by);
|
||||||
self.0.push(1);
|
self.0.truncate(level);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the first number of the state.
|
/// Get the first number of the state.
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
@ -104,3 +104,15 @@ At Beta, it was #context {
|
|||||||
#block(foo())
|
#block(foo())
|
||||||
#block(foo())
|
#block(foo())
|
||||||
#foo()
|
#foo()
|
||||||
|
|
||||||
|
--- issue-4626-counter-depth-skip ---
|
||||||
|
// When we step and skip a level, the levels should be filled with zeros, not
|
||||||
|
// with ones.
|
||||||
|
#let c = counter("c")
|
||||||
|
#context test(c.get(), (0,))
|
||||||
|
#c.step(level: 4)
|
||||||
|
#context test(c.get(), (0, 0, 0, 1))
|
||||||
|
#c.step(level: 1)
|
||||||
|
#context test(c.get(), (1,))
|
||||||
|
#c.step(level: 3)
|
||||||
|
#context test(c.get(), (1, 0, 1))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user