3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
+ import { ModifierKeyEmitter } from 'vs/base/browser/dom' ;
6
7
import { Event } from 'vs/base/common/event' ;
7
8
import { IDisposable } from 'vs/base/common/lifecycle' ;
8
9
import 'vs/css!./interactiveEditor' ;
@@ -29,7 +30,7 @@ import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/
29
30
30
31
export abstract class EditModeStrategy {
31
32
32
- dispose ( ) : void { }
33
+ abstract dispose ( ) : void ;
33
34
34
35
abstract checkChanges ( response : EditResponse ) : boolean ;
35
36
@@ -67,7 +68,6 @@ export class PreviewStrategy extends EditModeStrategy {
67
68
override dispose ( ) : void {
68
69
this . _listener . dispose ( ) ;
69
70
this . _ctxDocumentChanged . reset ( ) ;
70
- super . dispose ( ) ;
71
71
}
72
72
73
73
checkChanges ( response : EditResponse ) : boolean {
@@ -201,10 +201,11 @@ class InlineDiffDecorations {
201
201
export class LiveStrategy extends EditModeStrategy {
202
202
203
203
private static _inlineDiffStorageKey : string = 'interactiveEditor.storage.inlineDiff' ;
204
- private _inlineDiffEnabled : boolean = false ;
204
+ protected _diffEnabled : boolean = false ;
205
205
206
206
private readonly _inlineDiffDecorations : InlineDiffDecorations ;
207
- protected readonly _ctxShowingDiff : IContextKey < boolean > ;
207
+ private readonly _ctxShowingDiff : IContextKey < boolean > ;
208
+ private readonly _diffToggleListener : IDisposable ;
208
209
private _lastResponse ?: EditResponse ;
209
210
private _editCount : number = 0 ;
210
211
@@ -219,28 +220,36 @@ export class LiveStrategy extends EditModeStrategy {
219
220
@IInstantiationService private readonly _instaService : IInstantiationService ,
220
221
) {
221
222
super ( ) ;
222
- this . _inlineDiffDecorations = new InlineDiffDecorations ( this . _editor , this . _inlineDiffEnabled ) ;
223
+ this . _inlineDiffDecorations = new InlineDiffDecorations ( this . _editor , this . _diffEnabled ) ;
223
224
this . _ctxShowingDiff = CTX_INTERACTIVE_EDITOR_SHOWING_DIFF . bindTo ( contextKeyService ) ;
224
225
225
- this . _inlineDiffEnabled = _storageService . getBoolean ( LiveStrategy . _inlineDiffStorageKey , StorageScope . PROFILE , false ) ;
226
- this . _ctxShowingDiff . set ( this . _inlineDiffEnabled ) ;
227
- this . _inlineDiffDecorations . visible = this . _inlineDiffEnabled ;
226
+ this . _diffEnabled = _storageService . getBoolean ( LiveStrategy . _inlineDiffStorageKey , StorageScope . PROFILE , false ) ;
227
+ this . _ctxShowingDiff . set ( this . _diffEnabled ) ;
228
+ this . _inlineDiffDecorations . visible = this . _diffEnabled ;
229
+ this . _diffToggleListener = ModifierKeyEmitter . getInstance ( ) . event ( e => {
230
+ if ( e . altKey || e . lastKeyReleased === 'alt' ) {
231
+ this . toggleDiff ( ) ;
232
+ }
233
+ } ) ;
228
234
}
229
235
230
236
override dispose ( ) : void {
231
- this . _inlineDiffEnabled = this . _inlineDiffDecorations . visible ;
232
- this . _storageService . store ( LiveStrategy . _inlineDiffStorageKey , this . _inlineDiffEnabled , StorageScope . PROFILE , StorageTarget . USER ) ;
237
+ this . _diffToggleListener . dispose ( ) ;
238
+ this . _diffEnabled = this . _inlineDiffDecorations . visible ;
239
+ this . _storageService . store ( LiveStrategy . _inlineDiffStorageKey , this . _diffEnabled , StorageScope . PROFILE , StorageTarget . USER ) ;
233
240
this . _inlineDiffDecorations . clear ( ) ;
234
241
this . _ctxShowingDiff . reset ( ) ;
235
-
236
- super . dispose ( ) ;
237
242
}
238
243
239
244
toggleDiff ( ) : void {
240
- this . _inlineDiffEnabled = ! this . _inlineDiffEnabled ;
241
- this . _ctxShowingDiff . set ( this . _inlineDiffEnabled ) ;
242
- this . _inlineDiffDecorations . visible = this . _inlineDiffEnabled ;
243
- this . _storageService . store ( LiveStrategy . _inlineDiffStorageKey , this . _inlineDiffEnabled , StorageScope . PROFILE , StorageTarget . USER ) ;
245
+ this . _diffEnabled = ! this . _diffEnabled ;
246
+ this . _ctxShowingDiff . set ( this . _diffEnabled ) ;
247
+ this . _storageService . store ( LiveStrategy . _inlineDiffStorageKey , this . _diffEnabled , StorageScope . PROFILE , StorageTarget . USER ) ;
248
+ this . _doToggleDiff ( ) ;
249
+ }
250
+
251
+ protected _doToggleDiff ( ) : void {
252
+ this . _inlineDiffDecorations . visible = this . _diffEnabled ;
244
253
}
245
254
246
255
checkChanges ( response : EditResponse ) : boolean {
@@ -364,9 +373,10 @@ export class LivePreviewStrategy extends LiveStrategy {
364
373
365
374
override async renderChanges ( response : EditResponse ) {
366
375
367
- this . _diffZone . show ( ) ;
368
376
this . _updateSummaryMessage ( ) ;
369
- this . _ctxShowingDiff . set ( true ) ;
377
+ if ( this . _diffEnabled ) {
378
+ this . _diffZone . show ( ) ;
379
+ }
370
380
371
381
if ( response . singleCreateFileEdit ) {
372
382
this . _previewZone . showCreation ( this . _session . wholeRange , response . singleCreateFileEdit . uri , await Promise . all ( response . singleCreateFileEdit . edits ) ) ;
@@ -375,17 +385,16 @@ export class LivePreviewStrategy extends LiveStrategy {
375
385
}
376
386
}
377
387
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 . show ( ) ;
386
- this . _ctxShowingDiff . set ( true ) ;
388
+ protected override _doToggleDiff ( ) : void {
389
+ if ( this . _diffEnabled !== this . _diffZone . isVisible ) {
390
+ const scrollState = StableEditorScrollState . capture ( this . _editor ) ;
391
+ if ( this . _diffEnabled ) {
392
+ this . _diffZone . show ( ) ;
393
+ } else {
394
+ this . _diffZone . hide ( ) ;
395
+ }
396
+ scrollState . restore ( this . _editor ) ;
387
397
}
388
- scrollState . restore ( this . _editor ) ;
389
398
}
390
399
}
391
400
0 commit comments