last folding range not restored (#165390)

* last folding range not restored

* Update src/vs/editor/contrib/folding/browser/foldingRanges.ts

Co-authored-by: Tyler James Leonhardt <me@tylerleonhardt.com>

* Update src/vs/editor/contrib/folding/browser/foldingRanges.ts

Co-authored-by: Tyler James Leonhardt <me@tylerleonhardt.com>

* Update src/vs/editor/contrib/folding/browser/foldingRanges.ts

Co-authored-by: Tyler James Leonhardt <me@tylerleonhardt.com>

Co-authored-by: Tyler James Leonhardt <me@tylerleonhardt.com>
This commit is contained in:
Martin Aeschlimann 2022-11-03 18:15:23 +01:00 committed by GitHub
parent 5440af45a4
commit db48079fd1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View file

@ -183,8 +183,12 @@ export class FoldingModel {
public getMemento(): CollapseMemento | undefined {
const foldedOrManualRanges = this._currentFoldedOrManualRanges();
const result: ILineMemento[] = [];
const maxLineNumber = this._textModel.getLineCount();
for (let i = 0, limit = foldedOrManualRanges.length; i < limit; i++) {
const range = foldedOrManualRanges[i];
if (range.startLineNumber >= range.endLineNumber || range.startLineNumber < 1 || range.endLineNumber > maxLineNumber) {
continue;
}
const checksum = this._getLinesChecksum(range.startLineNumber + 1, range.endLineNumber);
result.push({
startLineNumber: range.startLineNumber,
@ -207,7 +211,7 @@ export class FoldingModel {
const rangesToRestore: FoldRange[] = [];
const maxLineNumber = this._textModel.getLineCount();
for (const range of state) {
if (range.startLineNumber >= range.endLineNumber || range.startLineNumber < 1 || range.endLineNumber >= maxLineNumber) {
if (range.startLineNumber >= range.endLineNumber || range.startLineNumber < 1 || range.endLineNumber > maxLineNumber) {
continue;
}
const checksum = this._getLinesChecksum(range.startLineNumber + 1, range.endLineNumber);

View file

@ -14,6 +14,12 @@ export const enum FoldSource {
recovered = 2
}
export const foldSourceAbbr = {
[FoldSource.provider]: ' ',
[FoldSource.userDefined]: 'u',
[FoldSource.recovered]: 'r',
};
export interface FoldRange {
startLineNumber: number;
endLineNumber: number;
@ -230,16 +236,11 @@ export class FoldingRegions {
return -1;
}
private readonly sourceAbbr = {
[FoldSource.provider]: ' ',
[FoldSource.userDefined]: 'u',
[FoldSource.recovered]: 'r',
};
public toString() {
const res: string[] = [];
for (let i = 0; i < this.length; i++) {
res[i] = `[${this.sourceAbbr[this.getSource(i)]}${this.isCollapsed(i) ? '+' : '-'}] ${this.getStartLineNumber(i)}/${this.getEndLineNumber(i)}`;
res[i] = `[${foldSourceAbbr[this.getSource(i)]}${this.isCollapsed(i) ? '+' : '-'}] ${this.getStartLineNumber(i)}/${this.getEndLineNumber(i)}`;
}
return res.join(', ');
}