@@ -17,7 +17,7 @@ import { ICommonCodeEditor, ScrollType } from 'vs/editor/common/editorCommon';
17
17
import { editorAction , ServicesAccessor , EditorAction , CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions' ;
18
18
import { ICodeEditor , IEditorMouseEvent , MouseTargetType } from 'vs/editor/browser/editorBrowser' ;
19
19
import { editorContribution } from 'vs/editor/browser/editorBrowserExtensions' ;
20
- import { FoldingModel , FoldingRegion , setCollapseStateAtLevel , setCollapseStateRecursivly , fold , unfold } from 'vs/editor/contrib/folding/common/foldingModel' ;
20
+ import { FoldingModel , setCollapseStateAtLevel , setCollapseStateRecursivly , fold , unfold , CollapseState } from 'vs/editor/contrib/folding/common/foldingModel' ;
21
21
import { computeRanges , limitByIndent } from 'vs/editor/contrib/folding/common/indentFoldStrategy' ;
22
22
import { FoldingDecorationProvider } from './foldingDecorations' ;
23
23
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys' ;
@@ -99,47 +99,35 @@ export class FoldingController {
99
99
/**
100
100
* Store view state.
101
101
*/
102
- public saveViewState ( ) : any {
102
+ public saveViewState ( ) : { collapsedRegions ?: CollapseState , lineCount ?: number } {
103
103
let model = this . editor . getModel ( ) ;
104
104
if ( ! model ) {
105
105
return { } ;
106
106
}
107
- let collapsedIndexes : number [ ] = [ ] ;
108
- for ( let region of this . foldingModel . regions ) {
109
- if ( region . isCollapsed && region . editorDecorationId ) {
110
- var range = model . getDecorationRange ( region . editorDecorationId ) ;
111
- if ( range ) {
112
- collapsedIndexes . push ( range . startLineNumber ) ;
113
- }
114
- }
115
- }
116
- return { collapsedIndexes, lineCount : model . getLineCount ( ) } ;
107
+ return { collapsedRegions : this . foldingModel . getCollapseState ( ) , lineCount : model . getLineCount ( ) } ;
117
108
}
118
109
119
110
/**
120
111
* Restore view state.
121
112
*/
122
- public restoreViewState ( state : any ) : void {
113
+ public restoreViewState ( state : { collapsedRegions ?: CollapseState , lineCount ?: number } ) : void {
123
114
let model = this . editor . getModel ( ) ;
124
115
if ( ! model ) {
125
116
return ;
126
117
}
127
118
if ( ! this . _isEnabled ) {
128
119
return ;
129
120
}
130
- if ( ! state || ! Array . isArray ( state . collapsedIndexes ) || state . collapsedIndexes . length === 0 || state . lineCount !== model . getLineCount ( ) ) {
121
+ if ( ! state || ! state . collapsedRegions || state . lineCount !== model . getLineCount ( ) ) {
131
122
return ;
132
123
}
133
- this . getFoldingModel ( ) . then ( foldingModel => {
134
- let toToogle : FoldingRegion [ ] = [ ] ;
135
- for ( let index of state . collapsedIndexes ) {
136
- let region = foldingModel . getRegionAtLine ( index ) ;
137
- if ( region && ! region . isCollapsed ) {
138
- toToogle . push ( region ) ;
139
- }
140
- }
141
- foldingModel . toggleCollapseState ( toToogle ) ;
142
- } ) ;
124
+
125
+ // set the hidden ranges right way, before waiting for the folding model.
126
+ if ( this . hiddenRangeModel . applyCollapseState ( state . collapsedRegions ) ) {
127
+ this . getFoldingModel ( ) . then ( foldingModel => {
128
+ foldingModel . applyCollapseState ( state . collapsedRegions ) ;
129
+ } ) ;
130
+ }
143
131
}
144
132
145
133
private onModelChanged ( ) : void {
0 commit comments