diff --git a/src/vs/workbench/browser/composite.ts b/src/vs/workbench/browser/composite.ts index 6414496a6d3..3a1eb2c4e6e 100644 --- a/src/vs/workbench/browser/composite.ts +++ b/src/vs/workbench/browser/composite.ts @@ -31,11 +31,11 @@ import { find } from 'vs/base/common/arrays'; */ export abstract class Composite extends Component implements IComposite { - private readonly _onTitleAreaUpdate: Emitter = this._register(new Emitter()); - readonly onTitleAreaUpdate: Event = this._onTitleAreaUpdate.event; + private readonly _onTitleAreaUpdate = this._register(new Emitter()); + readonly onTitleAreaUpdate = this._onTitleAreaUpdate.event; - private readonly _onDidChangeVisibility: Emitter = this._register(new Emitter()); - readonly onDidChangeVisibility: Event = this._onDidChangeVisibility.event; + private readonly _onDidChangeVisibility = this._register(new Emitter()); + readonly onDidChangeVisibility = this._onDidChangeVisibility.event; private _onDidFocus: Emitter | undefined; get onDidFocus(): Event { @@ -250,11 +250,11 @@ export abstract class CompositeDescriptor { export abstract class CompositeRegistry extends Disposable { - private readonly _onDidRegister: Emitter> = this._register(new Emitter>()); - get onDidRegister(): Event> { return this._onDidRegister.event; } + private readonly _onDidRegister = this._register(new Emitter>()); + readonly onDidRegister = this._onDidRegister.event; - private readonly _onDidDeregister: Emitter> = this._register(new Emitter>()); - get onDidDeregister(): Event> { return this._onDidDeregister.event; } + private readonly _onDidDeregister = this._register(new Emitter>()); + readonly onDidDeregister = this._onDidDeregister.event; private composites: CompositeDescriptor[] = []; diff --git a/src/vs/workbench/browser/parts/editor/editorAutoSave.ts b/src/vs/workbench/browser/parts/editor/editorAutoSave.ts index 0902582bf2a..b4eb3a41f04 100644 --- a/src/vs/workbench/browser/parts/editor/editorAutoSave.ts +++ b/src/vs/workbench/browser/parts/editor/editorAutoSave.ts @@ -9,7 +9,6 @@ import { IFilesConfigurationService, AutoSaveMode } from 'vs/workbench/services/ import { IHostService } from 'vs/workbench/services/host/browser/host'; import { SaveReason, IEditorIdentifier, IEditorInput, GroupIdentifier } from 'vs/workbench/common/editor'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; -import { ICodeEditor, isCodeEditor, isDiffEditor } from 'vs/editor/browser/editorBrowser'; import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; import { withNullAsUndefined } from 'vs/base/common/types'; @@ -57,19 +56,11 @@ export class EditorAutoSave extends Disposable implements IWorkbenchContribution this.lastActiveEditorControlDisposable.clear(); // Listen to focus changes on control for auto save - if (activeGroup && activeEditor) { - const activeTextEditorWidget = this.editorService.activeTextEditorWidget; - const controlsToObserve: ICodeEditor[] = []; - - if (isCodeEditor(activeTextEditorWidget)) { - controlsToObserve.push(activeTextEditorWidget); - } else if (isDiffEditor(activeTextEditorWidget)) { - controlsToObserve.push(activeTextEditorWidget.getOriginalEditor(), activeTextEditorWidget.getModifiedEditor()); - } - - controlsToObserve.forEach(control => this.lastActiveEditorControlDisposable.add(control.onDidBlurEditorWidget(() => { + const activeEditorControl = this.editorService.activeControl; + if (activeEditor && activeEditorControl) { + this.lastActiveEditorControlDisposable.add(activeEditorControl.onDidBlur(() => { this.maybeTriggerAutoSave(SaveReason.FOCUS_CHANGE, { groupId: activeGroup.id, editor: activeEditor }); - }))); + })); } } @@ -78,10 +69,9 @@ export class EditorAutoSave extends Disposable implements IWorkbenchContribution return; // no auto save for readonly or untitled editors } + // Determine if we need to save all. In case of a window focus change we also save if  + // auto save mode is configured to be ON_FOCUS_CHANGE (editor focus change) const mode = this.filesConfigurationService.getAutoSaveMode(); - - // Determine if we need to save all. In case of a window focus change we also save if auto save mode - // is configured to be ON_FOCUS_CHANGE (editor focus change) if ( (reason === SaveReason.WINDOW_CHANGE && (mode === AutoSaveMode.ON_FOCUS_CHANGE || mode === AutoSaveMode.ON_WINDOW_CHANGE)) || (reason === SaveReason.FOCUS_CHANGE && mode === AutoSaveMode.ON_FOCUS_CHANGE) diff --git a/src/vs/workbench/common/composite.ts b/src/vs/workbench/common/composite.ts index b6ea6f2ca73..8b48a7f4de8 100644 --- a/src/vs/workbench/common/composite.ts +++ b/src/vs/workbench/common/composite.ts @@ -4,9 +4,20 @@ *--------------------------------------------------------------------------------------------*/ import { IAction, IActionViewItem } from 'vs/base/common/actions'; +import { Event } from 'vs/base/common/event'; export interface IComposite { + /** + * An event when the composite gained focus. + */ + readonly onDidFocus: Event; + + /** + * An event when the composite lost focus. + */ + readonly onDidBlur: Event; + /** * Returns the unique identifier of this composite. */ diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 1ac273425c2..c2f430cfefe 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -23,6 +23,7 @@ import { coalesce, firstOrDefault } from 'vs/base/common/arrays'; import { ITextFileSaveOptions, ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { isEqual } from 'vs/base/common/resources'; +import { IPanel } from 'vs/workbench/common/panel'; export const DirtyWorkingCopiesContext = new RawContextKey('dirtyWorkingCopies', false); export const ActiveEditorContext = new RawContextKey('activeEditor', null); @@ -54,7 +55,7 @@ export const TEXT_DIFF_EDITOR_ID = 'workbench.editors.textDiffEditor'; */ export const BINARY_DIFF_EDITOR_ID = 'workbench.editors.binaryResourceDiffEditor'; -export interface IEditor { +export interface IEditor extends IPanel { /** * The assigned input of this editor. @@ -96,21 +97,11 @@ export interface IEditor { */ readonly onDidSizeConstraintsChange: Event<{ width: number; height: number; } | undefined>; - /** - * Returns the unique identifier of this editor. - */ - getId(): string; - /** * Returns the underlying control of this editor. */ getControl(): IEditorControl | undefined; - /** - * Asks the underlying control to focus. - */ - focus(): void; - /** * Finds out if this editor is visible or not. */ diff --git a/src/vs/workbench/services/progress/test/progressIndicator.test.ts b/src/vs/workbench/services/progress/test/progressIndicator.test.ts index 85a8e2f7275..f50511e22d8 100644 --- a/src/vs/workbench/services/progress/test/progressIndicator.test.ts +++ b/src/vs/workbench/services/progress/test/progressIndicator.test.ts @@ -11,11 +11,15 @@ import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; import { IPanelService } from 'vs/workbench/services/panel/common/panelService'; import { IViewlet } from 'vs/workbench/common/viewlet'; import { TestViewletService, TestPanelService } from 'vs/workbench/test/workbenchTestServices'; +import { Event } from 'vs/base/common/event'; class TestViewlet implements IViewlet { constructor(private id: string) { } + readonly onDidBlur = Event.None; + readonly onDidFocus = Event.None; + getId(): string { return this.id; } getTitle(): string { return this.id; } getActions(): IAction[] { return []; }