@@ -35,7 +35,7 @@ import { CustomTextEditorModel } from 'vs/workbench/contrib/customEditor/common/
3535import { WebviewExtensionDescription , WebviewIcons } from 'vs/workbench/contrib/webview/browser/webview' ;
3636import { WebviewInput } from 'vs/workbench/contrib/webview/browser/webviewEditorInput' ;
3737import { ICreateWebViewShowOptions , IWebviewWorkbenchService , WebviewInputOptions } from 'vs/workbench/contrib/webview/browser/webviewWorkbenchService' ;
38- import { IBackupFileService } from 'vs/workbench/services/backup/common/backup' ;
38+ import { IBackupFileService , IResolvedBackup } from 'vs/workbench/services/backup/common/backup' ;
3939import { IEditorGroup , IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService' ;
4040import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
4141import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions' ;
@@ -133,6 +133,7 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
133133 @ITelemetryService private readonly _telemetryService : ITelemetryService ,
134134 @IWebviewWorkbenchService private readonly _webviewWorkbenchService : IWebviewWorkbenchService ,
135135 @IInstantiationService private readonly _instantiationService : IInstantiationService ,
136+ @IBackupFileService private readonly _backupService : IBackupFileService ,
136137 ) {
137138 super ( ) ;
138139
@@ -410,7 +411,7 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
410411 : MainThreadCustomEditorModel . create ( this . _instantiationService , this . _proxy , viewType , resource , ( ) => {
411412 return Array . from ( this . _webviewInputs )
412413 . filter ( editor => editor instanceof CustomEditorInput && isEqual ( editor . resource , resource ) ) as CustomEditorInput [ ] ;
413- } , cancellation ) ;
414+ } , cancellation , this . _backupService ) ;
414415
415416 return this . _customEditorService . models . add ( resource , viewType , model ) ;
416417 }
@@ -577,7 +578,7 @@ namespace HotExitState {
577578 readonly type = Type . Pending ;
578579
579580 constructor (
580- public readonly operation : CancelablePromise < void > ,
581+ public readonly operation : CancelablePromise < string > ,
581582 ) { }
582583 }
583584
@@ -600,58 +601,58 @@ class MainThreadCustomEditorModel extends Disposable implements ICustomEditorMod
600601 resource : URI ,
601602 getEditors : ( ) => CustomEditorInput [ ] ,
602603 cancellation : CancellationToken ,
604+ backupFileService : IBackupFileService ,
603605 ) {
604- const { editable } = await proxy . $createWebviewCustomEditorDocument ( resource , viewType , cancellation ) ;
605- const model = instantiationService . createInstance ( MainThreadCustomEditorModel , proxy , viewType , resource , editable , getEditors ) ;
606- await model . init ( ) ;
607- return model ;
606+ const backup = await backupFileService . resolve < CustomDocumentBackupData > ( MainThreadCustomEditorModel . toWorkingCopyResource ( viewType , resource ) ) ;
607+ const { editable } = await proxy . $createCustomDocument ( resource , viewType , backup ?. meta ?. backupId , cancellation ) ;
608+ return instantiationService . createInstance ( MainThreadCustomEditorModel , proxy , viewType , resource , backup , editable , getEditors ) ;
608609 }
609610
610611 constructor (
611612 private readonly _proxy : extHostProtocol . ExtHostWebviewsShape ,
612613 private readonly _viewType : string ,
613614 private readonly _editorResource : URI ,
615+ backup : IResolvedBackup < CustomDocumentBackupData > | undefined ,
614616 private readonly _editable : boolean ,
615617 private readonly _getEditors : ( ) => CustomEditorInput [ ] ,
616618 @IWorkingCopyService workingCopyService : IWorkingCopyService ,
617619 @ILabelService private readonly _labelService : ILabelService ,
618620 @IFileService private readonly _fileService : IFileService ,
619621 @IUndoRedoService private readonly _undoService : IUndoRedoService ,
620- @IBackupFileService private readonly _backupFileService : IBackupFileService ,
621622 ) {
622623 super ( ) ;
623624
624625 if ( _editable ) {
625626 this . _register ( workingCopyService . registerWorkingCopy ( this ) ) ;
626627 }
628+ this . _fromBackup = ! ! backup ;
627629 }
628630
629631 get editorResource ( ) {
630632 return this . _editorResource ;
631633 }
632634
633- async init ( ) : Promise < void > {
634- const backup = await this . _backupFileService . resolve < CustomDocumentBackupData > ( this . resource ) ;
635- this . _fromBackup = ! ! backup ;
636- }
637-
638635 dispose ( ) {
639636 if ( this . _editable ) {
640637 this . _undoService . removeElements ( this . _editorResource ) ;
641638 }
642- this . _proxy . $disposeWebviewCustomEditorDocument ( this . _editorResource , this . _viewType ) ;
639+ this . _proxy . $disposeCustomDocument ( this . _editorResource , this . _viewType ) ;
643640 super . dispose ( ) ;
644641 }
645642
646643 //#region IWorkingCopy
647644
648645 public get resource ( ) {
649646 // Make sure each custom editor has a unique resource for backup and edits
647+ return MainThreadCustomEditorModel . toWorkingCopyResource ( this . _viewType , this . _editorResource ) ;
648+ }
649+
650+ private static toWorkingCopyResource ( viewType : string , resource : URI ) {
650651 return URI . from ( {
651652 scheme : Schemas . vscodeCustomEditor ,
652- authority : this . _viewType ,
653- path : this . _editorResource . path ,
654- query : JSON . stringify ( this . _editorResource . toJSON ( ) ) ,
653+ authority : viewType ,
654+ path : resource . path ,
655+ query : JSON . stringify ( resource . toJSON ( ) ) ,
655656 } ) ;
656657 }
657658
@@ -719,15 +720,7 @@ class MainThreadCustomEditorModel extends Disposable implements ICustomEditorMod
719720 this . change ( ( ) => {
720721 -- this . _currentEditIndex ;
721722 } ) ;
722- await this . _proxy . $undo ( this . _editorResource , this . viewType , undoneEdit , this . getEditState ( ) ) ;
723- }
724-
725- private getEditState ( ) : extHostProtocol . CustomDocumentEditState {
726- return {
727- allEdits : this . _edits ,
728- currentIndex : this . _currentEditIndex ,
729- saveIndex : this . _savePoint ,
730- } ;
723+ await this . _proxy . $undo ( this . _editorResource , this . viewType , undoneEdit , this . isDirty ( ) ) ;
731724 }
732725
733726 private async redo ( ) : Promise < void > {
@@ -744,7 +737,7 @@ class MainThreadCustomEditorModel extends Disposable implements ICustomEditorMod
744737 this . change ( ( ) => {
745738 ++ this . _currentEditIndex ;
746739 } ) ;
747- await this . _proxy . $redo ( this . _editorResource , this . viewType , redoneEdit , this . getEditState ( ) ) ;
740+ await this . _proxy . $redo ( this . _editorResource , this . viewType , redoneEdit , this . isDirty ( ) ) ;
748741 }
749742
750743 private spliceEdits ( editToInsert ?: number ) {
@@ -779,16 +772,7 @@ class MainThreadCustomEditorModel extends Disposable implements ICustomEditorMod
779772 return ;
780773 }
781774
782- let editsToUndo : number [ ] = [ ] ;
783- let editsToRedo : number [ ] = [ ] ;
784-
785- if ( this . _currentEditIndex >= this . _savePoint ) {
786- editsToUndo = this . _edits . slice ( this . _savePoint , this . _currentEditIndex ) . reverse ( ) ;
787- } else if ( this . _currentEditIndex < this . _savePoint ) {
788- editsToRedo = this . _edits . slice ( this . _currentEditIndex , this . _savePoint ) ;
789- }
790-
791- this . _proxy . $revert ( this . _editorResource , this . viewType , { undoneEdits : editsToUndo , redoneEdits : editsToRedo } , this . getEditState ( ) ) ;
775+ this . _proxy . $revert ( this . _editorResource , this . viewType , CancellationToken . None ) ;
792776 this . change ( ( ) => {
793777 this . _currentEditIndex = this . _savePoint ;
794778 this . spliceEdits ( ) ;
@@ -838,6 +822,7 @@ class MainThreadCustomEditorModel extends Disposable implements ICustomEditorMod
838822 meta : {
839823 viewType : this . viewType ,
840824 editorResource : this . _editorResource ,
825+ backupId : '' ,
841826 extension : primaryEditor . extension ? {
842827 id : primaryEditor . extension . id . value ,
843828 location : primaryEditor . extension . location ,
@@ -864,10 +849,11 @@ class MainThreadCustomEditorModel extends Disposable implements ICustomEditorMod
864849 this . _hotExitState = pendingState ;
865850
866851 try {
867- await pendingState . operation ;
852+ const backupId = await pendingState . operation ;
868853 // Make sure state has not changed in the meantime
869854 if ( this . _hotExitState === pendingState ) {
870855 this . _hotExitState = HotExitState . Allowed ;
856+ backupData . meta ! . backupId = backupId ;
871857 }
872858 } catch ( e ) {
873859 // Make sure state has not changed in the meantime
0 commit comments