diff --git a/packages/plugin-ext/src/main/browser/custom-editors/custom-editors-main.ts b/packages/plugin-ext/src/main/browser/custom-editors/custom-editors-main.ts index 724d64215758a..73511bf102426 100644 --- a/packages/plugin-ext/src/main/browser/custom-editors/custom-editors-main.ts +++ b/packages/plugin-ext/src/main/browser/custom-editors/custom-editors-main.ts @@ -185,7 +185,7 @@ export class CustomEditorsMainImpl implements CustomEditorsMain, Disposable { switch (modelType) { case CustomEditorModelType.Text: { - const model = CustomTextEditorModel.create(viewType, resource, this.textModelService, this.fileService); + const model = CustomTextEditorModel.create(viewType, resource, this.textModelService, this.fileService, this.editorPreferences); return this.customEditorService.models.add(resource, viewType, model); } case CustomEditorModelType.Custom: { @@ -520,24 +520,27 @@ export class CustomTextEditorModel implements CustomEditorModel { private readonly toDispose = new DisposableCollection(); private readonly onDirtyChangedEmitter = new Emitter(); readonly onDirtyChanged = this.onDirtyChangedEmitter.event; - readonly autoSave: 'off' | 'afterDelay' | 'onFocusChange' | 'onWindowChange'; + autoSave: 'off' | 'afterDelay' | 'onFocusChange' | 'onWindowChange'; + autoSaveDelay: number; static async create( viewType: string, resource: TheiaURI, editorModelService: EditorModelService, - fileService: FileService + fileService: FileService, + editorPreferences: EditorPreferences, ): Promise { const model = await editorModelService.createModelReference(resource); model.object.suppressOpenEditorWhenDirty = true; - return new CustomTextEditorModel(viewType, resource, model, fileService); + return new CustomTextEditorModel(viewType, resource, model, fileService, editorPreferences); } constructor( readonly viewType: string, readonly editorResource: TheiaURI, private readonly model: Reference, - private readonly fileService: FileService + private readonly fileService: FileService, + private readonly editorPreferences: EditorPreferences ) { this.toDispose.push( this.editorTextModel.onDirtyChanged(e => { @@ -545,6 +548,21 @@ export class CustomTextEditorModel implements CustomEditorModel { }) ); this.toDispose.push(this.onDirtyChangedEmitter); + + this.autoSave = this.editorPreferences.get('files.autoSave', undefined, editorResource.toString()); + this.autoSaveDelay = this.editorPreferences.get('files.autoSaveDelay', undefined, editorResource.toString()); + + this.toDispose.push( + this.editorPreferences.onPreferenceChanged(event => { + if (event.preferenceName === 'files.autoSave') { + this.autoSave = this.editorPreferences.get('files.autoSave', undefined, editorResource.toString()); + } + if (event.preferenceName === 'files.autoSaveDelay') { + this.autoSaveDelay = this.editorPreferences.get('files.autoSaveDelay', undefined, editorResource.toString()); + } + }) + ); + this.toDispose.push(this.onDirtyChangedEmitter); } dispose(): void {