@@ -8,11 +8,11 @@ import { IDisposable } from 'vs/base/common/lifecycle';
8
8
import 'vs/css!./interactiveEditor' ;
9
9
import { ICodeEditor } from 'vs/editor/browser/editorBrowser' ;
10
10
import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService' ;
11
+ import { StableEditorScrollState } from 'vs/editor/browser/stableEditorScroll' ;
11
12
import { EditOperation , ISingleEditOperation } from 'vs/editor/common/core/editOperation' ;
12
13
import { Position } from 'vs/editor/common/core/position' ;
13
14
import { Range } from 'vs/editor/common/core/range' ;
14
15
import { Selection } from 'vs/editor/common/core/selection' ;
15
- import { LineRangeMapping } from 'vs/editor/common/diff/linesDiffComputer' ;
16
16
import { IEditorDecorationsCollection } from 'vs/editor/common/editorCommon' ;
17
17
import { ICursorStateComputer , IModelDecorationOptions , IModelDeltaDecoration , IValidEditOperation } from 'vs/editor/common/model' ;
18
18
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorker' ;
@@ -24,7 +24,7 @@ import { InteractiveEditorFileCreatePreviewWidget, InteractiveEditorLivePreviewW
24
24
import { EditResponse , Session } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorSession' ;
25
25
import { InteractiveEditorWidget } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorWidget' ;
26
26
import { getValueFromSnapshot } from 'vs/workbench/contrib/interactiveEditor/browser/utils' ;
27
- import { CTX_INTERACTIVE_EDITOR_INLNE_DIFF , CTX_INTERACTIVE_EDITOR_DOCUMENT_CHANGED } from 'vs/workbench/contrib/interactiveEditor/common/interactiveEditor' ;
27
+ import { CTX_INTERACTIVE_EDITOR_SHOWING_DIFF , CTX_INTERACTIVE_EDITOR_DOCUMENT_CHANGED } from 'vs/workbench/contrib/interactiveEditor/common/interactiveEditor' ;
28
28
import { IEditorService , SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService' ;
29
29
30
30
export abstract class EditModeStrategy {
@@ -39,9 +39,9 @@ export abstract class EditModeStrategy {
39
39
40
40
abstract makeChanges ( response : EditResponse , edits : ISingleEditOperation [ ] ) : Promise < void > ;
41
41
42
- abstract renderChanges ( response : EditResponse , changes : LineRangeMapping [ ] ) : Promise < void > ;
42
+ abstract renderChanges ( response : EditResponse ) : Promise < void > ;
43
43
44
- abstract toggleInlineDiff ( ) : void ;
44
+ abstract toggleDiff ( ) : void ;
45
45
}
46
46
47
47
export class PreviewStrategy extends EditModeStrategy {
@@ -111,10 +111,10 @@ export class PreviewStrategy extends EditModeStrategy {
111
111
// nothing to do
112
112
}
113
113
114
- override async renderChanges ( response : EditResponse , changes : LineRangeMapping [ ] ) : Promise < void > {
114
+ override async renderChanges ( response : EditResponse ) : Promise < void > {
115
115
if ( response . localEdits . length > 0 ) {
116
116
const edits = response . localEdits . map ( edit => EditOperation . replace ( Range . lift ( edit . range ) , edit . text ) ) ;
117
- this . _widget . showEditsPreview ( this . _session . textModel0 , edits , changes ) ;
117
+ this . _widget . showEditsPreview ( this . _session . textModel0 , edits , this . _session . lastTextModelChanges ) ;
118
118
} else {
119
119
this . _widget . hideEditsPreview ( ) ;
120
120
}
@@ -126,7 +126,9 @@ export class PreviewStrategy extends EditModeStrategy {
126
126
}
127
127
}
128
128
129
- toggleInlineDiff ( ) : void { }
129
+ toggleDiff ( ) : void {
130
+ // nothing to do
131
+ }
130
132
}
131
133
132
134
class InlineDiffDecorations {
@@ -202,7 +204,7 @@ export class LiveStrategy extends EditModeStrategy {
202
204
private _inlineDiffEnabled : boolean = false ;
203
205
204
206
private readonly _inlineDiffDecorations : InlineDiffDecorations ;
205
- private readonly _ctxInlineDiff : IContextKey < boolean > ;
207
+ protected readonly _ctxShowingDiff : IContextKey < boolean > ;
206
208
private _lastResponse ?: EditResponse ;
207
209
private _editCount : number = 0 ;
208
210
@@ -218,25 +220,25 @@ export class LiveStrategy extends EditModeStrategy {
218
220
) {
219
221
super ( ) ;
220
222
this . _inlineDiffDecorations = new InlineDiffDecorations ( this . _editor , this . _inlineDiffEnabled ) ;
221
- this . _ctxInlineDiff = CTX_INTERACTIVE_EDITOR_INLNE_DIFF . bindTo ( contextKeyService ) ;
223
+ this . _ctxShowingDiff = CTX_INTERACTIVE_EDITOR_SHOWING_DIFF . bindTo ( contextKeyService ) ;
222
224
223
225
this . _inlineDiffEnabled = _storageService . getBoolean ( LiveStrategy . _inlineDiffStorageKey , StorageScope . PROFILE , false ) ;
224
- this . _ctxInlineDiff . set ( this . _inlineDiffEnabled ) ;
226
+ this . _ctxShowingDiff . set ( this . _inlineDiffEnabled ) ;
225
227
this . _inlineDiffDecorations . visible = this . _inlineDiffEnabled ;
226
228
}
227
229
228
230
override dispose ( ) : void {
229
231
this . _inlineDiffEnabled = this . _inlineDiffDecorations . visible ;
230
232
this . _storageService . store ( LiveStrategy . _inlineDiffStorageKey , this . _inlineDiffEnabled , StorageScope . PROFILE , StorageTarget . USER ) ;
231
233
this . _inlineDiffDecorations . clear ( ) ;
232
- this . _ctxInlineDiff . reset ( ) ;
234
+ this . _ctxShowingDiff . reset ( ) ;
233
235
234
236
super . dispose ( ) ;
235
237
}
236
238
237
- toggleInlineDiff ( ) : void {
239
+ toggleDiff ( ) : void {
238
240
this . _inlineDiffEnabled = ! this . _inlineDiffEnabled ;
239
- this . _ctxInlineDiff . set ( this . _inlineDiffEnabled ) ;
241
+ this . _ctxShowingDiff . set ( this . _inlineDiffEnabled ) ;
240
242
this . _inlineDiffDecorations . visible = this . _inlineDiffEnabled ;
241
243
this . _storageService . store ( LiveStrategy . _inlineDiffStorageKey , this . _inlineDiffEnabled , StorageScope . PROFILE , StorageTarget . USER ) ;
242
244
}
@@ -298,10 +300,10 @@ export class LiveStrategy extends EditModeStrategy {
298
300
this . _editor . executeEdits ( 'interactive-editor-live' , edits , ignoreInlineDiff ? undefined : cursorStateComputerAndInlineDiffCollection ) ;
299
301
}
300
302
301
- override async renderChanges ( response : EditResponse , textModel0Changes : LineRangeMapping [ ] ) {
303
+ override async renderChanges ( response : EditResponse ) {
302
304
303
305
this . _inlineDiffDecorations . update ( ) ;
304
- this . _updateSummaryMessage ( textModel0Changes ) ;
306
+ this . _updateSummaryMessage ( ) ;
305
307
306
308
if ( response . singleCreateFileEdit ) {
307
309
this . _widget . showCreatePreview ( response . singleCreateFileEdit . uri , await Promise . all ( response . singleCreateFileEdit . edits ) ) ;
@@ -310,12 +312,10 @@ export class LiveStrategy extends EditModeStrategy {
310
312
}
311
313
}
312
314
313
- protected _updateSummaryMessage ( textModel0Changes : LineRangeMapping [ ] ) {
315
+ protected _updateSummaryMessage ( ) {
314
316
let linesChanged = 0 ;
315
- if ( textModel0Changes ) {
316
- for ( const change of textModel0Changes ) {
317
- linesChanged += change . changedLineCount ;
318
- }
317
+ for ( const change of this . _session . lastTextModelChanges ) {
318
+ linesChanged += change . changedLineCount ;
319
319
}
320
320
let message : string ;
321
321
if ( linesChanged === 0 ) {
@@ -346,7 +346,7 @@ export class LivePreviewStrategy extends LiveStrategy {
346
346
) {
347
347
super ( session , editor , widget , contextKeyService , storageService , bulkEditService , editorWorkerService , instaService ) ;
348
348
349
- this . _diffZone = instaService . createInstance ( InteractiveEditorLivePreviewWidget , editor , session . textModel0 ) ;
349
+ this . _diffZone = instaService . createInstance ( InteractiveEditorLivePreviewWidget , editor , session ) ;
350
350
this . _previewZone = instaService . createInstance ( InteractiveEditorFileCreatePreviewWidget , editor ) ;
351
351
}
352
352
@@ -362,17 +362,31 @@ export class LivePreviewStrategy extends LiveStrategy {
362
362
super . makeChanges ( _response , edits , true ) ;
363
363
}
364
364
365
- override async renderChanges ( response : EditResponse , changes : LineRangeMapping [ ] ) {
365
+ override async renderChanges ( response : EditResponse ) {
366
366
367
- this . _diffZone . showDiff ( ( ) => this . _session . wholeRange , changes ) ;
368
- this . _updateSummaryMessage ( changes ) ;
367
+ this . _diffZone . showDiff ( ) ;
368
+ this . _updateSummaryMessage ( ) ;
369
+ this . _ctxShowingDiff . set ( true ) ;
369
370
370
371
if ( response . singleCreateFileEdit ) {
371
372
this . _previewZone . showCreation ( this . _session . wholeRange , response . singleCreateFileEdit . uri , await Promise . all ( response . singleCreateFileEdit . edits ) ) ;
372
373
} else {
373
374
this . _previewZone . hide ( ) ;
374
375
}
375
376
}
377
+
378
+ override toggleDiff ( ) : void {
379
+ // TODO@jrieken should this be persisted like we do in live-mode?
380
+ const scrollState = StableEditorScrollState . capture ( this . _editor ) ;
381
+ if ( this . _diffZone . isVisible ) {
382
+ this . _diffZone . hide ( ) ;
383
+ this . _ctxShowingDiff . set ( false ) ;
384
+ } else {
385
+ this . _diffZone . showDiff ( ) ;
386
+ this . _ctxShowingDiff . set ( true ) ;
387
+ }
388
+ scrollState . restore ( this . _editor ) ;
389
+ }
376
390
}
377
391
378
392
function showSingleCreateFile ( accessor : ServicesAccessor , edit : EditResponse ) {
0 commit comments