@@ -8,7 +8,7 @@ import { Disposable } from 'vs/base/common/lifecycle';
8
8
import { IObservable , IReader , ISettableObservable , ITransaction , derived , observableSignal , observableSignalFromEvent , observableValue , transaction , waitForState } from 'vs/base/common/observable' ;
9
9
import { autorunWithStore2 } from 'vs/base/common/observableImpl/autorun' ;
10
10
import { isDefined } from 'vs/base/common/types' ;
11
- import { LineRange } from 'vs/editor/common/core/lineRange' ;
11
+ import { ISerializedLineRange , LineRange } from 'vs/editor/common/core/lineRange' ;
12
12
import { Range } from 'vs/editor/common/core/range' ;
13
13
import { IDocumentDiff , IDocumentDiffProvider } from 'vs/editor/common/diff/documentDiffProvider' ;
14
14
import { LineRangeMapping , MovedText , RangeMapping , SimpleLineRangeMapping } from 'vs/editor/common/diff/linesDiffComputer' ;
@@ -137,20 +137,6 @@ export class DiffEditorViewModel extends Disposable implements IDiffEditorViewMo
137
137
. filter ( r => ! ! r )
138
138
. map ( r => LineRange . fromRange ( r ! ) ) ;
139
139
140
- for ( const r of newUnchangedRegions ) {
141
- for ( let i = 0 ; i < lastUnchangedRegions . regions . length ; i ++ ) {
142
- if ( r . originalRange . intersectsStrict ( lastUnchangedRegionsOrigRanges [ i ] )
143
- && r . modifiedRange . intersectsStrict ( lastUnchangedRegionsModRanges [ i ] ) ) {
144
- r . setState (
145
- lastUnchangedRegions . regions [ i ] . visibleLineCountTop . get ( ) ,
146
- lastUnchangedRegions . regions [ i ] . visibleLineCountBottom . get ( ) ,
147
- undefined ,
148
- ) ;
149
- break ;
150
- }
151
- }
152
- }
153
-
154
140
const originalDecorationIds = model . original . deltaDecorations (
155
141
lastUnchangedRegions . originalDecorationIds ,
156
142
newUnchangedRegions . map ( r => ( { range : r . originalRange . toInclusiveRange ( ) ! , options : { description : 'unchanged' } } ) )
@@ -161,6 +147,16 @@ export class DiffEditorViewModel extends Disposable implements IDiffEditorViewMo
161
147
) ;
162
148
163
149
transaction ( tx => {
150
+ for ( const r of newUnchangedRegions ) {
151
+ for ( let i = 0 ; i < lastUnchangedRegions . regions . length ; i ++ ) {
152
+ if ( r . originalRange . intersectsStrict ( lastUnchangedRegionsOrigRanges [ i ] )
153
+ && r . modifiedRange . intersectsStrict ( lastUnchangedRegionsModRanges [ i ] ) ) {
154
+ r . setHiddenModifiedRange ( lastUnchangedRegions . regions [ i ] . getHiddenModifiedRange ( undefined ) , tx ) ;
155
+ break ;
156
+ }
157
+ }
158
+ }
159
+
164
160
this . _lastDiff = result ;
165
161
this . _diff . set ( DiffState . fromDiffResult ( result ) , tx ) ;
166
162
this . _isDiffUpToDate . set ( true , tx ) ;
@@ -208,6 +204,32 @@ export class DiffEditorViewModel extends Disposable implements IDiffEditorViewMo
208
204
public async waitForDiff ( ) : Promise < void > {
209
205
await waitForState ( this . isDiffUpToDate , s => s ) ;
210
206
}
207
+
208
+ public serializeState ( ) : SerializedState {
209
+ const regions = this . _unchangedRegions . get ( ) ;
210
+ return {
211
+ collapsedRegions : regions . regions . map ( r => ( { range : r . getHiddenModifiedRange ( undefined ) . serialize ( ) } ) )
212
+ } ;
213
+ }
214
+
215
+ public restoreSerializedState ( state : SerializedState ) : void {
216
+ const ranges = state . collapsedRegions . map ( r => LineRange . deserialize ( r . range ) ) ;
217
+ const regions = this . _unchangedRegions . get ( ) ;
218
+ transaction ( tx => {
219
+ for ( const r of regions . regions ) {
220
+ for ( const range of ranges ) {
221
+ if ( r . modifiedRange . intersect ( range ) ) {
222
+ r . setHiddenModifiedRange ( range , tx ) ;
223
+ break ;
224
+ }
225
+ }
226
+ }
227
+ } ) ;
228
+ }
229
+ }
230
+
231
+ interface SerializedState {
232
+ collapsedRegions : { range : ISerializedLineRange } [ ] ;
211
233
}
212
234
213
235
export class DiffState {
@@ -334,6 +356,12 @@ export class UnchangedRegion {
334
356
) ;
335
357
}
336
358
359
+ public setHiddenModifiedRange ( range : LineRange , tx : ITransaction ) {
360
+ const visibleLineCountTop = range . startLineNumber - this . modifiedLineNumber ;
361
+ const visibleLineCountBottom = ( this . modifiedLineNumber + this . lineCount ) - range . endLineNumberExclusive ;
362
+ this . setState ( visibleLineCountTop , visibleLineCountBottom , tx ) ;
363
+ }
364
+
337
365
public getMaxVisibleLineCountTop ( ) {
338
366
return this . lineCount - this . _visibleLineCountBottom . get ( ) ;
339
367
}
@@ -357,8 +385,8 @@ export class UnchangedRegion {
357
385
}
358
386
359
387
public setState ( visibleLineCountTop : number , visibleLineCountBottom : number , tx : ITransaction | undefined ) : void {
360
- visibleLineCountTop = Math . min ( visibleLineCountTop , this . lineCount ) ;
361
- visibleLineCountBottom = Math . min ( visibleLineCountBottom , this . lineCount - visibleLineCountTop ) ;
388
+ visibleLineCountTop = Math . max ( Math . min ( visibleLineCountTop , this . lineCount ) , 0 ) ;
389
+ visibleLineCountBottom = Math . max ( Math . min ( visibleLineCountBottom , this . lineCount - visibleLineCountTop ) , 0 ) ;
362
390
363
391
this . _visibleLineCountTop . set ( visibleLineCountTop , tx ) ;
364
392
this . _visibleLineCountBottom . set ( visibleLineCountBottom , tx ) ;
0 commit comments