From 32262c4bdd8f9a63c48d7a80a6d12acdea4e5be0 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Tue, 15 Aug 2017 12:54:24 +0200 Subject: [PATCH] Slow to switch to/from tab with large collapsed section. Fixes #32330 --- .../editor/contrib/folding/browser/folding.ts | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/vs/editor/contrib/folding/browser/folding.ts b/src/vs/editor/contrib/folding/browser/folding.ts index 25f7677b107..45af63c8b99 100644 --- a/src/vs/editor/contrib/folding/browser/folding.ts +++ b/src/vs/editor/contrib/folding/browser/folding.ts @@ -123,14 +123,33 @@ export class FoldingController implements IFoldingController { if (!state || !Array.isArray(state.collapsedRegions) || state.collapsedRegions.length === 0 || state.lineCount !== model.getLineCount()) { return; } + let newFolded = state.collapsedRegions; - // State should be applied on the clean state - // Clean the state - this.cleanState(); - // apply state - this.applyRegions(state.collapsedRegions); - // Start listening to the model - this.onModelChanged(); + if (this.decorations.length > 0) { + let hasChanges = false; + let i = 0; + this.editor.changeDecorations(changeAccessor => { + this.decorations.forEach(d => { + if (i === newFolded.length || d.startLineNumber < newFolded[i].startLineNumber) { + if (d.isCollapsed) { + d.setCollapsed(false, changeAccessor); + hasChanges = true; + } + } else if (d.startLineNumber === newFolded[i].startLineNumber) { + if (!d.isCollapsed) { + d.setCollapsed(true, changeAccessor); + hasChanges = true; + } + i++; + } else { + return; // folding regions doesn't match, don't try to restore + } + }); + }); + if (hasChanges) { + this.updateHiddenAreas(void 0); + } + } } private cleanState(): void { -- GitLab