提交 0defcabe 编写于 作者: B Benjamin Pasero

debt - do NOT use window.onFocus/onBlur

This ensures that e.g. clicking into an iframe of a <webview> does not accidentally trigger blur events with upcoming Electron 3.0.x
上级 468ade67
......@@ -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')) {
......
......@@ -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 {
......
......@@ -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);
}
}
......@@ -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<IModifierKeyStatus> {
private _keyStatus: IModifierKeyStatus;
private static instance: ModifierKeyEmitter;
private constructor() {
private constructor(windowService: IWindowService) {
super();
this._keyStatus = {
......@@ -1350,20 +1350,22 @@ class ModifierKeyEmitter extends Emitter<IModifierKeyStatus> {
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;
......
......@@ -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())));
......
......@@ -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)));
......
......@@ -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 {
......
......@@ -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;
}
......
......@@ -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[] {
......
......@@ -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();
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册