4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
import { Event } from 'vs/base/common/event' ;
7
+ import { Lazy } from 'vs/base/common/lazy' ;
7
8
import { IDisposable } from 'vs/base/common/lifecycle' ;
8
9
import { ICodeEditor } from 'vs/editor/browser/editorBrowser' ;
9
10
import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService' ;
@@ -347,8 +348,8 @@ export class LiveStrategy extends EditModeStrategy {
347
348
348
349
export class LivePreviewStrategy extends LiveStrategy {
349
350
350
- private readonly _diffZone : InlineChatLivePreviewWidget ;
351
- private readonly _previewZone : InlineChatFileCreatePreviewWidget ;
351
+ private readonly _diffZone : Lazy < InlineChatLivePreviewWidget > ;
352
+ private readonly _previewZone : Lazy < InlineChatFileCreatePreviewWidget > ;
352
353
353
354
constructor (
354
355
session : Session ,
@@ -362,49 +363,49 @@ export class LivePreviewStrategy extends LiveStrategy {
362
363
) {
363
364
super ( session , editor , widget , contextKeyService , storageService , bulkEditService , editorWorkerService , instaService ) ;
364
365
365
- this . _diffZone = instaService . createInstance ( InlineChatLivePreviewWidget , editor , session ) ;
366
- this . _previewZone = instaService . createInstance ( InlineChatFileCreatePreviewWidget , editor ) ;
366
+ this . _diffZone = new Lazy ( ( ) => instaService . createInstance ( InlineChatLivePreviewWidget , editor , session ) ) ;
367
+ this . _previewZone = new Lazy ( ( ) => instaService . createInstance ( InlineChatFileCreatePreviewWidget , editor ) ) ;
367
368
}
368
369
369
370
override dispose ( ) : void {
370
- this . _diffZone . hide ( ) ;
371
- this . _diffZone . dispose ( ) ;
372
- this . _previewZone . hide ( ) ;
373
- this . _previewZone . dispose ( ) ;
371
+ this . _diffZone . rawValue ?. hide ( ) ;
372
+ this . _diffZone . rawValue ?. dispose ( ) ;
373
+ this . _previewZone . rawValue ?. hide ( ) ;
374
+ this . _previewZone . rawValue ?. dispose ( ) ;
374
375
super . dispose ( ) ;
375
376
}
376
377
377
378
override async renderChanges ( response : EditResponse ) {
378
379
379
380
this . _updateSummaryMessage ( ) ;
380
381
if ( this . _diffEnabled ) {
381
- this . _diffZone . show ( ) ;
382
+ this . _diffZone . value . show ( ) ;
382
383
}
383
384
384
385
if ( response . singleCreateFileEdit ) {
385
- this . _previewZone . showCreation ( this . _session . wholeRange . value , response . singleCreateFileEdit . uri , await Promise . all ( response . singleCreateFileEdit . edits ) ) ;
386
+ this . _previewZone . value . showCreation ( this . _session . wholeRange . value , response . singleCreateFileEdit . uri , await Promise . all ( response . singleCreateFileEdit . edits ) ) ;
386
387
} else {
387
- this . _previewZone . hide ( ) ;
388
+ this . _previewZone . value . hide ( ) ;
388
389
}
389
390
}
390
391
391
392
override async undoChanges ( response : EditResponse ) : Promise < void > {
392
- this . _diffZone . lockToDiff ( ) ;
393
+ this . _diffZone . value . lockToDiff ( ) ;
393
394
super . undoChanges ( response ) ;
394
395
}
395
396
396
397
protected override _doToggleDiff ( ) : void {
397
398
const scrollState = StableEditorScrollState . capture ( this . _editor ) ;
398
399
if ( this . _diffEnabled ) {
399
- this . _diffZone . show ( ) ;
400
+ this . _diffZone . value . show ( ) ;
400
401
} else {
401
- this . _diffZone . hide ( ) ;
402
+ this . _diffZone . value . hide ( ) ;
402
403
}
403
404
scrollState . restore ( this . _editor ) ;
404
405
}
405
406
406
407
override hasFocus ( ) : boolean {
407
- return super . hasFocus ( ) || this . _diffZone . hasFocus ( ) || this . _previewZone . hasFocus ( ) ;
408
+ return super . hasFocus ( ) || this . _diffZone . value . hasFocus ( ) || this . _previewZone . value . hasFocus ( ) ;
408
409
}
409
410
}
410
411
0 commit comments