Skip to content

Commit

Permalink
last folding range not restored (#165390)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
aeschli and TylerLeonhardt authored Nov 3, 2022
1 parent 5440af4 commit db48079
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/vs/editor/contrib/folding/browser/foldingModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
13 changes: 7 additions & 6 deletions src/vs/editor/contrib/folding/browser/foldingRanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(', ');
}
Expand Down

0 comments on commit db48079

Please sign in to comment.