Skip to content

Commit

Permalink
fix(counter-style): handle decreasing ranges properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jsamr committed Apr 13, 2021
1 parent 397e76f commit 2315975
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ describe('CounterStyleRenderer', () => {
);
});
describe('::maxMarkerLenInRange', () => {
it('should return 0 when range is decreasing', () => {
const counter = decimal;
expect(counter.maxMarkerLenInRange(1, 0)).toBe(0);
expect(counter.maxCounterLenInRange(1, 0)).toBe(0);
});
it('should work with numeric styles', () => {
const counter = decimal;
expect(counter.maxMarkerLenInRange(1, 9)).toBe(1 + DEFAULT_SUFFIX.length);
Expand Down
6 changes: 6 additions & 0 deletions packages/counter-style/src/makeCSRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const stylePrototype: Omit<CounterStyleRendererInt, 'engine'> = {
return Math.max(lenLeft, lenMiddle, lenRight);
},
maxCounterLenInRange(this: CounterStyleRendererInt, min, max) {
if (max < min) {
return 0;
}
if (min >= 0) {
return this.getAbsoluteMaxLenInRange(min, max, false);
}
Expand All @@ -55,6 +58,9 @@ const stylePrototype: Omit<CounterStyleRendererInt, 'engine'> = {
);
},
maxMarkerLenInRange(this: CounterStyleRendererInt, min, max) {
if (max < min) {
return 0;
}
return (
this.maxCounterLenInRange(min, max) +
codeunitLength(this.engine.specs.suffix) +
Expand Down

0 comments on commit 2315975

Please sign in to comment.