[html] return max number of ranges (for #46687)
This commit is contained in:
parent
8a07c8d935
commit
752acd5042
2 changed files with 14 additions and 5 deletions
|
@ -87,5 +87,14 @@ function limitRanges(ranges: FoldingRange[], maxRanges: number) {
|
|||
entries += n;
|
||||
}
|
||||
}
|
||||
return ranges.filter((r, index) => (typeof nestingLevels[index] === 'number') && nestingLevels[index] < maxLevel);
|
||||
let result = [];
|
||||
for (let i = 0; i < ranges.length; i++) {
|
||||
let level = nestingLevels[i];
|
||||
if (typeof level === 'number') {
|
||||
if (level < maxLevel || (level === maxLevel && entries++ < maxRanges)) {
|
||||
result.push(ranges[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -204,11 +204,11 @@ suite('HTML Folding', () => {
|
|||
];
|
||||
assertRanges(input, [r(0, 19), r(1, 18), r(2, 3), r(5, 11), r(6, 7), r(9, 10), r(13, 14), r(16, 17)], 'no limit', void 0);
|
||||
assertRanges(input, [r(0, 19), r(1, 18), r(2, 3), r(5, 11), r(6, 7), r(9, 10), r(13, 14), r(16, 17)], 'limit 8', 8);
|
||||
assertRanges(input, [r(0, 19), r(1, 18), r(2, 3), r(5, 11), r(13, 14), r(16, 17)], 'limit 7', 7);
|
||||
assertRanges(input, [r(0, 19), r(1, 18), r(2, 3), r(5, 11), r(6, 7), r(13, 14), r(16, 17)], 'limit 7', 7);
|
||||
assertRanges(input, [r(0, 19), r(1, 18), r(2, 3), r(5, 11), r(13, 14), r(16, 17)], 'limit 6', 6);
|
||||
assertRanges(input, [r(0, 19), r(1, 18)], 'limit 5', 5);
|
||||
assertRanges(input, [r(0, 19), r(1, 18)], 'limit 4', 4);
|
||||
assertRanges(input, [r(0, 19), r(1, 18)], 'limit 3', 3);
|
||||
assertRanges(input, [r(0, 19), r(1, 18), r(2, 3), r(5, 11), r(13, 14)], 'limit 5', 5);
|
||||
assertRanges(input, [r(0, 19), r(1, 18), r(2, 3), r(5, 11)], 'limit 4', 4);
|
||||
assertRanges(input, [r(0, 19), r(1, 18), r(2, 3)], 'limit 3', 3);
|
||||
assertRanges(input, [r(0, 19), r(1, 18)], 'limit 2', 2);
|
||||
assertRanges(input, [r(0, 19)], 'limit 1', 1);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue