From 41a8fa188756d8fa66b5f23eccc362fb0cfd3568 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Thu, 3 Nov 2022 17:25:16 +0100 Subject: [PATCH 1/4] last folding range not restored --- .../contrib/folding/browser/foldingModel.ts | 6 +++++- .../contrib/folding/browser/foldingRanges.ts | 17 +++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/vs/editor/contrib/folding/browser/foldingModel.ts b/src/vs/editor/contrib/folding/browser/foldingModel.ts index 3b212ff6abb27..543df6931620f 100644 --- a/src/vs/editor/contrib/folding/browser/foldingModel.ts +++ b/src/vs/editor/contrib/folding/browser/foldingModel.ts @@ -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); diff --git a/src/vs/editor/contrib/folding/browser/foldingRanges.ts b/src/vs/editor/contrib/folding/browser/foldingRanges.ts index 8beb820778dc2..a2553339be6ee 100644 --- a/src/vs/editor/contrib/folding/browser/foldingRanges.ts +++ b/src/vs/editor/contrib/folding/browser/foldingRanges.ts @@ -14,6 +14,13 @@ export const enum FoldSource { recovered = 2 } +export const foldSourceAbbr = { + [FoldSource.provider]: ' ', + [FoldSource.userDefined]: 'u', + [FoldSource.recovered]: 'r', +}; + + export interface FoldRange { startLineNumber: number; endLineNumber: number; @@ -52,6 +59,8 @@ class BitField { } } + + export class FoldingRegions { private readonly _startIndexes: Uint32Array; private readonly _endIndexes: Uint32Array; @@ -230,16 +239,12 @@ 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(', '); } From 537ca93f3753e7a6d58b9176a0335729e0ff7f49 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Thu, 3 Nov 2022 17:40:26 +0100 Subject: [PATCH 2/4] Update src/vs/editor/contrib/folding/browser/foldingRanges.ts Co-authored-by: Tyler James Leonhardt --- src/vs/editor/contrib/folding/browser/foldingRanges.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/vs/editor/contrib/folding/browser/foldingRanges.ts b/src/vs/editor/contrib/folding/browser/foldingRanges.ts index a2553339be6ee..cfa20f2d2f28b 100644 --- a/src/vs/editor/contrib/folding/browser/foldingRanges.ts +++ b/src/vs/editor/contrib/folding/browser/foldingRanges.ts @@ -20,7 +20,6 @@ export const foldSourceAbbr = { [FoldSource.recovered]: 'r', }; - export interface FoldRange { startLineNumber: number; endLineNumber: number; From 74000f10ad875f27d91f0c858efdcbd06158fb58 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Thu, 3 Nov 2022 17:40:32 +0100 Subject: [PATCH 3/4] Update src/vs/editor/contrib/folding/browser/foldingRanges.ts Co-authored-by: Tyler James Leonhardt --- src/vs/editor/contrib/folding/browser/foldingRanges.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/vs/editor/contrib/folding/browser/foldingRanges.ts b/src/vs/editor/contrib/folding/browser/foldingRanges.ts index cfa20f2d2f28b..2808ecdbcd94b 100644 --- a/src/vs/editor/contrib/folding/browser/foldingRanges.ts +++ b/src/vs/editor/contrib/folding/browser/foldingRanges.ts @@ -239,7 +239,6 @@ export class FoldingRegions { } - public toString() { const res: string[] = []; for (let i = 0; i < this.length; i++) { From 01256dd36d93d4fc49a373b55f8ace61a12c0c81 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Thu, 3 Nov 2022 17:40:39 +0100 Subject: [PATCH 4/4] Update src/vs/editor/contrib/folding/browser/foldingRanges.ts Co-authored-by: Tyler James Leonhardt --- src/vs/editor/contrib/folding/browser/foldingRanges.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/vs/editor/contrib/folding/browser/foldingRanges.ts b/src/vs/editor/contrib/folding/browser/foldingRanges.ts index 2808ecdbcd94b..5c800345b4826 100644 --- a/src/vs/editor/contrib/folding/browser/foldingRanges.ts +++ b/src/vs/editor/contrib/folding/browser/foldingRanges.ts @@ -58,8 +58,6 @@ class BitField { } } - - export class FoldingRegions { private readonly _startIndexes: Uint32Array; private readonly _endIndexes: Uint32Array;