Fixes counter stepping behavior (#4631)

Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
Johann Birnick 2024-08-05 13:02:04 +02:00 committed by GitHub
parent 9909f12d4f
commit 211b546e4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 6 deletions

View File

@ -685,14 +685,12 @@ impl CounterState {
pub fn step(&mut self, level: NonZeroUsize, by: usize) {
let level = level.get();
if self.0.len() >= level {
self.0[level - 1] = self.0[level - 1].saturating_add(by);
self.0.truncate(level);
while self.0.len() < level {
self.0.push(0);
}
while self.0.len() < level {
self.0.push(1);
}
self.0[level - 1] = self.0[level - 1].saturating_add(by);
self.0.truncate(level);
}
/// Get the first number of the state.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

View File

@ -104,3 +104,15 @@ At Beta, it was #context {
#block(foo())
#block(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))