Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix webview focus steal that occurs when the application is re-focused #98847

Merged
merged 7 commits into from Jul 13, 2020
5 changes: 4 additions & 1 deletion src/vs/workbench/contrib/webview/browser/webviewEditor.ts
Expand Up @@ -19,6 +19,7 @@ import { WebviewInput } from 'vs/workbench/contrib/webview/browser/webviewEditor
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IHostService } from 'vs/workbench/services/host/browser/host';
import { IWorkbenchLayoutService, Parts } from 'vs/workbench/services/layout/browser/layoutService';

export class WebviewEditor extends BaseEditor {

Expand All @@ -39,6 +40,8 @@ export class WebviewEditor extends BaseEditor {
@IThemeService themeService: IThemeService,
@IStorageService storageService: IStorageService,
@IEditorService private readonly _editorService: IEditorService,
@IWorkbenchLayoutService private readonly _workbenchLayoutService: IWorkbenchLayoutService,
@IEditorGroupsService private readonly _editorGroupsService: IEditorGroupsService,
@IEditorDropService private readonly _editorDropService: IEditorDropService,
@IHostService private readonly _hostService: IHostService,
) {
Expand Down Expand Up @@ -76,7 +79,7 @@ export class WebviewEditor extends BaseEditor {
if (!this._onFocusWindowHandler.value && !isWeb) {
// Make sure we restore focus when switching back to a VS Code window
this._onFocusWindowHandler.value = this._hostService.onDidChangeFocus(focused => {
if (focused && this._editorService.activeEditorPane === this) {
if (focused && this._editorService.activeEditorPane === this && this._workbenchLayoutService.hasFocus(Parts.EDITOR_PART)) {
this.focus();
}
});
Expand Down