Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

last folding range not restored #165390

Merged
merged 4 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
};

aeschli marked this conversation as resolved.
Show resolved Hide resolved
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