diff --git a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts index de98bed575e8b5a8e9d458f1cc5de36d544495c4..946fa38e116ef085f46827115088a252c2640e3e 100644 --- a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts +++ b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts @@ -37,6 +37,7 @@ import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorG import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { CancellationToken } from 'vs/base/common/cancellation'; import { EditorMemento } from 'vs/workbench/browser/parts/editor/baseEditor'; +import { IWindowService } from 'vs/platform/windows/common/windows'; /** * The text editor that leverages the diff text editor for the editing experience. @@ -61,8 +62,9 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor { @IThemeService themeService: IThemeService, @IEditorGroupsService editorGroupService: IEditorGroupsService, @ITextFileService textFileService: ITextFileService, + @IWindowService windowService: IWindowService ) { - super(TextDiffEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService, editorService, editorGroupService); + super(TextDiffEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService, editorService, editorGroupService, windowService); this._register(this._actualConfigurationService.onDidChangeConfiguration((e) => { if (e.affectsConfiguration('diffEditor.ignoreTrimWhitespace')) { diff --git a/src/vs/workbench/browser/parts/editor/textEditor.ts b/src/vs/workbench/browser/parts/editor/textEditor.ts index 50ff252902e533f2dd1e9678865973a872801c43..aaa22f85ad44bccd5313d0e62bc4130dc2ebeea5 100644 --- a/src/vs/workbench/browser/parts/editor/textEditor.ts +++ b/src/vs/workbench/browser/parts/editor/textEditor.ts @@ -26,6 +26,7 @@ import { isDiffEditor, isCodeEditor, ICodeEditor, getCodeEditor } from 'vs/edito import { IEditorGroupsService, IEditorGroup } from 'vs/workbench/services/group/common/editorGroupsService'; import { CancellationToken } from 'vs/base/common/cancellation'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; +import { IWindowService } from 'vs/platform/windows/common/windows'; const TEXT_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'textEditorViewState'; @@ -55,6 +56,7 @@ export abstract class BaseTextEditor extends BaseEditor implements ITextEditor { @ITextFileService private readonly _textFileService: ITextFileService, @IEditorService protected editorService: IEditorService, @IEditorGroupsService protected editorGroupService: IEditorGroupsService, + @IWindowService private windowService: IWindowService ) { super(id, telemetryService, themeService); @@ -148,15 +150,17 @@ export abstract class BaseTextEditor extends BaseEditor implements ITextEditor { } this._register(this.editorService.onDidActiveEditorChange(() => this.onEditorFocusLost())); - this._register(DOM.addDisposableListener(window, DOM.EventType.BLUR, () => this.onWindowFocusLost())); + this._register(this.windowService.onDidChangeFocus(focused => this.onWindowFocusChange(focused))); } private onEditorFocusLost(): void { this.maybeTriggerSaveAll(SaveReason.FOCUS_CHANGE); } - private onWindowFocusLost(): void { - this.maybeTriggerSaveAll(SaveReason.WINDOW_CHANGE); + private onWindowFocusChange(focused: boolean): void { + if (!focused) { + this.maybeTriggerSaveAll(SaveReason.WINDOW_CHANGE); + } } private maybeTriggerSaveAll(reason: SaveReason): void { diff --git a/src/vs/workbench/browser/parts/editor/textResourceEditor.ts b/src/vs/workbench/browser/parts/editor/textResourceEditor.ts index 0c0d212617b1540940cd00f9aadf825f39e9e625..dfa60893d52a903e9d6d720920d8c0243f144051 100644 --- a/src/vs/workbench/browser/parts/editor/textResourceEditor.ts +++ b/src/vs/workbench/browser/parts/editor/textResourceEditor.ts @@ -25,6 +25,7 @@ import { ScrollType } from 'vs/editor/common/editorCommon'; import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService'; import { CancellationToken } from 'vs/base/common/cancellation'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; +import { IWindowService } from 'vs/platform/windows/common/windows'; /** * An editor implementation that is capable of showing the contents of resource inputs. Uses @@ -41,9 +42,10 @@ export class AbstractTextResourceEditor extends BaseTextEditor { @IThemeService themeService: IThemeService, @IEditorGroupsService editorGroupService: IEditorGroupsService, @ITextFileService textFileService: ITextFileService, - @IEditorService editorService: IEditorService + @IEditorService editorService: IEditorService, + @IWindowService windowService: IWindowService ) { - super(id, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService, editorService, editorGroupService); + super(id, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService, editorService, editorGroupService, windowService); } getTitle(): string { @@ -210,8 +212,9 @@ export class TextResourceEditor extends AbstractTextResourceEditor { @IThemeService themeService: IThemeService, @ITextFileService textFileService: ITextFileService, @IEditorService editorService: IEditorService, - @IEditorGroupsService editorGroupService: IEditorGroupsService + @IEditorGroupsService editorGroupService: IEditorGroupsService, + @IWindowService windowService: IWindowService ) { - super(TextResourceEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, editorGroupService, textFileService, editorService); + super(TextResourceEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, editorGroupService, textFileService, editorService, windowService); } } diff --git a/src/vs/workbench/browser/parts/titlebar/menubarControl.ts b/src/vs/workbench/browser/parts/titlebar/menubarControl.ts index 5afaac786b05575c5740f71287ec503b71e3b58d..7b1d4e42698671aa84e2015d91886102eaf564ef 100644 --- a/src/vs/workbench/browser/parts/titlebar/menubarControl.ts +++ b/src/vs/workbench/browser/parts/titlebar/menubarControl.ts @@ -455,7 +455,7 @@ export class MenubarControl extends Disposable { this._register(browser.onDidChangeFullscreen(() => this.onDidChangeFullscreen())); // Listen for alt key presses - this._register(ModifierKeyEmitter.getInstance().event(this.onModifierKeyToggled, this)); + this._register(ModifierKeyEmitter.getInstance(this.windowService).event(this.onModifierKeyToggled, this)); // Listen for window focus changes this._register(this.windowService.onDidChangeFocus(e => this.onDidChangeWindowFocus(e))); @@ -1291,7 +1291,7 @@ class ModifierKeyEmitter extends Emitter { private _keyStatus: IModifierKeyStatus; private static instance: ModifierKeyEmitter; - private constructor() { + private constructor(windowService: IWindowService) { super(); this._keyStatus = { @@ -1350,20 +1350,22 @@ class ModifierKeyEmitter extends Emitter { this._keyStatus.lastKeyPressed = undefined; })); - this._subscriptions.push(domEvent(window, 'blur')(e => { - this._keyStatus.lastKeyPressed = undefined; - this._keyStatus.lastKeyReleased = undefined; - this._keyStatus.altKey = false; - this._keyStatus.shiftKey = false; - this._keyStatus.shiftKey = false; + this._subscriptions.push(windowService.onDidChangeFocus(focused => { + if (!focused) { + this._keyStatus.lastKeyPressed = undefined; + this._keyStatus.lastKeyReleased = undefined; + this._keyStatus.altKey = false; + this._keyStatus.shiftKey = false; + this._keyStatus.shiftKey = false; - this.fire(this._keyStatus); + this.fire(this._keyStatus); + } })); } - static getInstance() { + static getInstance(windowService: IWindowService) { if (!ModifierKeyEmitter.instance) { - ModifierKeyEmitter.instance = new ModifierKeyEmitter(); + ModifierKeyEmitter.instance = new ModifierKeyEmitter(windowService); } return ModifierKeyEmitter.instance; diff --git a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts index eea5df0a6e04b19e94f2c2e8e097d5392180aa4a..6fbd7fd2be617ee3d0601ef32ee012c33c9441a5 100644 --- a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts +++ b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts @@ -30,7 +30,7 @@ import { isMacintosh, isWindows, isLinux } from 'vs/base/common/platform'; import URI from 'vs/base/common/uri'; import { Color } from 'vs/base/common/color'; import { trim } from 'vs/base/common/strings'; -import { addDisposableListener, EventType, EventHelper, Dimension, isAncestor } from 'vs/base/browser/dom'; +import { EventType, EventHelper, Dimension, isAncestor } from 'vs/base/browser/dom'; import { MenubarControl } from 'vs/workbench/browser/parts/titlebar/menubarControl'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { template, getBaseLabel } from 'vs/base/common/labels'; @@ -95,8 +95,7 @@ export class TitlebarPart extends Part implements ITitleService { } private registerListeners(): void { - this._register(addDisposableListener(window, EventType.BLUR, () => this.onBlur())); - this._register(addDisposableListener(window, EventType.FOCUS, () => this.onFocus())); + this._register(this.windowService.onDidChangeFocus(focused => focused ? this.onFocus() : this.onBlur())); this._register(this.configurationService.onDidChangeConfiguration(e => this.onConfigurationChanged(e))); this._register(this.editorService.onDidActiveEditorChange(() => this.onActiveEditorChange())); this._register(this.contextService.onDidChangeWorkspaceFolders(() => this.setTitle(this.getWindowTitle()))); diff --git a/src/vs/workbench/parts/files/browser/editors/textFileEditor.ts b/src/vs/workbench/parts/files/browser/editors/textFileEditor.ts index ee794e4861d3636618521f2755f13a08ebbb0580..db50f8b784c2d74d6245d46bff60f6d0e349ddc1 100644 --- a/src/vs/workbench/parts/files/browser/editors/textFileEditor.ts +++ b/src/vs/workbench/parts/files/browser/editors/textFileEditor.ts @@ -28,7 +28,7 @@ import { IPreferencesService } from 'vs/workbench/services/preferences/common/pr import { PreferencesEditor } from 'vs/workbench/parts/preferences/browser/preferencesEditor'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { ScrollType } from 'vs/editor/common/editorCommon'; -import { IWindowsService } from 'vs/platform/windows/common/windows'; +import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IEditorGroupsService, IEditorGroup } from 'vs/workbench/services/group/common/editorGroupsService'; import { CancellationToken } from 'vs/base/common/cancellation'; @@ -54,9 +54,10 @@ export class TextFileEditor extends BaseTextEditor { @IEditorGroupsService editorGroupService: IEditorGroupsService, @ITextFileService textFileService: ITextFileService, @IWindowsService private windowsService: IWindowsService, - @IPreferencesService private preferencesService: IPreferencesService + @IPreferencesService private preferencesService: IPreferencesService, + @IWindowService windowService: IWindowService ) { - super(TextFileEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService, editorService, editorGroupService); + super(TextFileEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService, editorService, editorGroupService, windowService); // Clear view state for deleted files this._register(this.fileService.onFileChanges(e => this.onFilesChanged(e))); diff --git a/src/vs/workbench/parts/output/browser/logViewer.ts b/src/vs/workbench/parts/output/browser/logViewer.ts index 69588a3fd2461c1a867e2867500ad2da18405068..ef79e9b3a0ac08e266a6e6523bd5f42c1deba841 100644 --- a/src/vs/workbench/parts/output/browser/logViewer.ts +++ b/src/vs/workbench/parts/output/browser/logViewer.ts @@ -20,6 +20,7 @@ import { IHashService } from 'vs/workbench/services/hash/common/hashService'; import { LOG_SCHEME } from 'vs/workbench/parts/output/common/output'; import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; +import { IWindowService } from 'vs/platform/windows/common/windows'; export class LogViewerInput extends ResourceEditorInput { @@ -54,9 +55,10 @@ export class LogViewer extends AbstractTextResourceEditor { @IThemeService themeService: IThemeService, @IEditorGroupsService editorGroupService: IEditorGroupsService, @ITextFileService textFileService: ITextFileService, - @IEditorService editorService: IEditorService + @IEditorService editorService: IEditorService, + @IWindowService windowService: IWindowService ) { - super(LogViewer.LOG_VIEWER_EDITOR_ID, telemetryService, instantiationService, storageService, textResourceConfigurationService, themeService, editorGroupService, textFileService, editorService); + super(LogViewer.LOG_VIEWER_EDITOR_ID, telemetryService, instantiationService, storageService, textResourceConfigurationService, themeService, editorGroupService, textFileService, editorService, windowService); } protected getConfigurationOverrides(): IEditorOptions { diff --git a/src/vs/workbench/parts/output/browser/outputPanel.ts b/src/vs/workbench/parts/output/browser/outputPanel.ts index 0cc33ce78b50f5cfde03bf990cf76f98f15c5574..4753c5b88f0a573b992d9a115eef8304062814ce 100644 --- a/src/vs/workbench/parts/output/browser/outputPanel.ts +++ b/src/vs/workbench/parts/output/browser/outputPanel.ts @@ -25,6 +25,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService'; import { CancellationToken } from 'vs/base/common/cancellation'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; +import { IWindowService } from 'vs/platform/windows/common/windows'; export class OutputPanel extends AbstractTextResourceEditor { private actions: IAction[]; @@ -41,9 +42,10 @@ export class OutputPanel extends AbstractTextResourceEditor { @IContextKeyService private contextKeyService: IContextKeyService, @IEditorGroupsService editorGroupService: IEditorGroupsService, @ITextFileService textFileService: ITextFileService, - @IEditorService editorService: IEditorService + @IEditorService editorService: IEditorService, + @IWindowService windowService: IWindowService ) { - super(OUTPUT_PANEL_ID, telemetryService, instantiationService, storageService, textResourceConfigurationService, themeService, editorGroupService, textFileService, editorService); + super(OUTPUT_PANEL_ID, telemetryService, instantiationService, storageService, textResourceConfigurationService, themeService, editorGroupService, textFileService, editorService, windowService); this.scopedInstantiationService = instantiationService; } diff --git a/src/vs/workbench/parts/preferences/browser/preferencesEditor.ts b/src/vs/workbench/parts/preferences/browser/preferencesEditor.ts index cd658aea042326fc9a5af273e325e99f7083712f..450538341697460831ea71783cd25b26e11a6779 100644 --- a/src/vs/workbench/parts/preferences/browser/preferencesEditor.ts +++ b/src/vs/workbench/parts/preferences/browser/preferencesEditor.ts @@ -55,6 +55,7 @@ import { IFilterResult, IPreferencesService, ISearchResult, ISetting, ISettingsE import { DefaultPreferencesEditorInput, PreferencesEditorInput } from 'vs/workbench/services/preferences/common/preferencesEditorInput'; import { DefaultSettingsEditorModel, SettingsEditorModel } from 'vs/workbench/services/preferences/common/preferencesModels'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; +import { IWindowService } from 'vs/platform/windows/common/windows'; export class PreferencesEditor extends BaseEditor { @@ -975,9 +976,10 @@ export class DefaultPreferencesEditor extends BaseTextEditor { @IThemeService themeService: IThemeService, @ITextFileService textFileService: ITextFileService, @IEditorGroupsService editorGroupService: IEditorGroupsService, - @IEditorService editorService: IEditorService + @IEditorService editorService: IEditorService, + @IWindowService windowService: IWindowService ) { - super(DefaultPreferencesEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService, editorService, editorGroupService); + super(DefaultPreferencesEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService, editorService, editorGroupService, windowService); } private static _getContributions(): IEditorContributionCtor[] { diff --git a/src/vs/workbench/parts/webview/electron-browser/webviewEditor.ts b/src/vs/workbench/parts/webview/electron-browser/webviewEditor.ts index 24e9760e39d4dca857725154222a521887796fa2..1c6aae711b05c531c38beab0a1fdb049c8ca5472 100644 --- a/src/vs/workbench/parts/webview/electron-browser/webviewEditor.ts +++ b/src/vs/workbench/parts/webview/electron-browser/webviewEditor.ts @@ -4,7 +4,6 @@ *--------------------------------------------------------------------------------------------*/ import * as DOM from 'vs/base/browser/dom'; -import { domEvent } from 'vs/base/browser/event'; import { CancellationToken } from 'vs/base/common/cancellation'; import { Emitter, Event } from 'vs/base/common/event'; import { IDisposable } from 'vs/base/common/lifecycle'; @@ -21,6 +20,7 @@ import { IEditorGroup } from 'vs/workbench/services/group/common/editorGroupsSer import { IPartService, Parts } from 'vs/workbench/services/part/common/partService'; import { BaseWebviewEditor, KEYBINDING_CONTEXT_WEBVIEWEDITOR_FIND_WIDGET_INPUT_FOCUSED, KEYBINDING_CONTEXT_WEBVIEWEDITOR_FOCUS, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE } from './baseWebviewEditor'; import { WebviewElement } from './webviewElement'; +import { IWindowService } from 'vs/platform/windows/common/windows'; export class WebviewEditor extends BaseWebviewEditor { @@ -43,7 +43,8 @@ export class WebviewEditor extends BaseWebviewEditor { @IPartService private readonly _partService: IPartService, @IWorkspaceContextService private readonly _contextService: IWorkspaceContextService, @IInstantiationService private readonly _instantiationService: IInstantiationService, - @IEditorService private readonly _editorService: IEditorService + @IEditorService private readonly _editorService: IEditorService, + @IWindowService private readonly _windowService: IWindowService ) { super(WebviewEditor.ID, telemetryService, themeService, _contextKeyService); } @@ -82,8 +83,8 @@ export class WebviewEditor extends BaseWebviewEditor { } // Make sure we restore focus when switching back to a VS Code window - this._onFocusWindowHandler = domEvent(window, 'focus')(() => { - if (this._editorService.activeControl === this) { + this._onFocusWindowHandler = this._windowService.onDidChangeFocus(focused => { + if (focused && this._editorService.activeControl === this) { this.focus(); } });