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 electron webviews not always updating _webviewKeyboardHandler when focus changes #163495

Merged
merged 1 commit into from Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/vs/workbench/contrib/webview/browser/webviewElement.ts
Expand Up @@ -37,7 +37,7 @@ import { areWebviewContentOptionsEqual, IWebview, WebviewContentOptions, Webview
import { WebviewFindDelegate, WebviewFindWidget } from 'vs/workbench/contrib/webview/browser/webviewFindWidget';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';

export const enum WebviewMessageChannels {
const enum WebviewMessageChannels {
onmessage = 'onmessage',
didClickLink = 'did-click-link',
didScroll = 'did-scroll',
Expand Down Expand Up @@ -303,14 +303,14 @@ export class WebviewElement extends Disposable implements IWebview, WebviewFindD
this.handleFocusChange(true);
}));

this._register(this.on(WebviewMessageChannels.wheel, (event: IMouseWheelEvent) => {
this._onDidWheel.fire(event);
}));

this._register(this.on(WebviewMessageChannels.didBlur, () => {
this.handleFocusChange(false);
}));

this._register(this.on(WebviewMessageChannels.wheel, (event: IMouseWheelEvent) => {
this._onDidWheel.fire(event);
}));

this._register(this.on(WebviewMessageChannels.didFind, (didFind: boolean) => {
this._hasFindResult.fire(didFind);
}));
Expand Down Expand Up @@ -379,7 +379,6 @@ export class WebviewElement extends Disposable implements IWebview, WebviewFindD
}));

this._register(Event.runAndSubscribe(webviewThemeDataProvider.onThemeDataChanged, () => this.style()));

this._register(_accessibilityService.onDidChangeReducedMotion(() => this.style()));
this._register(_accessibilityService.onDidChangeScreenReaderOptimized(() => this.style()));

Expand Down Expand Up @@ -468,7 +467,7 @@ export class WebviewElement extends Disposable implements IWebview, WebviewFindD
return this._send('message', { message, transfer });
}

protected async _send(channel: string, data?: any, transferable: Transferable[] = []): Promise<boolean> {
private async _send(channel: string, data?: any, transferable: Transferable[] = []): Promise<boolean> {
if (this._state.type === WebviewState.Type.Initializing) {
let resolve: (x: boolean) => void;
const promise = new Promise<boolean>(r => resolve = r);
Expand Down Expand Up @@ -525,7 +524,6 @@ export class WebviewElement extends Disposable implements IWebview, WebviewFindD
params.purpose = options.purpose;
}


COI.addSearchParam(params, true, true);

const queryString = new URLSearchParams(params).toString();
Expand Down Expand Up @@ -596,7 +594,7 @@ export class WebviewElement extends Disposable implements IWebview, WebviewFindD
return false;
}

protected on<T = unknown>(channel: WebviewMessageChannels, handler: (data: T, e: MessageEvent) => void): IDisposable {
private on<T = unknown>(channel: WebviewMessageChannels, handler: (data: T, e: MessageEvent) => void): IDisposable {
let handlers = this._messageHandlers.get(channel);
if (!handlers) {
handlers = new Set();
Expand Down Expand Up @@ -724,7 +722,7 @@ export class WebviewElement extends Disposable implements IWebview, WebviewFindD
this._webviewFindWidget?.updateTheme(this.webviewThemeDataProvider.getTheme());
}

private handleFocusChange(isFocused: boolean): void {
protected handleFocusChange(isFocused: boolean): void {
this._focused = isFocused;
if (isFocused) {
this._onDidFocus.fire();
Expand Down
Expand Up @@ -23,7 +23,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ITunnelService } from 'vs/platform/tunnel/common/tunnel';
import { FindInFrameOptions, IWebviewManagerService } from 'vs/platform/webview/common/webviewManagerService';
import { WebviewThemeDataProvider } from 'vs/workbench/contrib/webview/browser/themeing';
import { WebviewElement, WebviewInitInfo, WebviewMessageChannels } from 'vs/workbench/contrib/webview/browser/webviewElement';
import { WebviewElement, WebviewInitInfo } from 'vs/workbench/contrib/webview/browser/webviewElement';
import { WindowIgnoreMenuShortcutsManager } from 'vs/workbench/contrib/webview/electron-sandbox/windowIgnoreMenuShortcutsManager';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';

Expand Down Expand Up @@ -68,14 +68,6 @@ export class ElectronWebviewElement extends WebviewElement {

this._webviewMainService = ProxyChannel.toService<IWebviewManagerService>(mainProcessService.getChannel('webview'));

this._register(this.on(WebviewMessageChannels.didFocus, () => {
this._webviewKeyboardHandler.didFocus();
}));

this._register(this.on(WebviewMessageChannels.didBlur, () => {
this._webviewKeyboardHandler.didBlur();
}));

if (initInfo.options.enableFindWidget) {
this._register(this.onDidHtmlChange((newContent) => {
if (this._findStarted && this._cachedHtmlContent !== newContent) {
Expand Down Expand Up @@ -167,4 +159,13 @@ export class ElectronWebviewElement extends WebviewElement {
});
this._onDidStopFind.fire();
}

protected override handleFocusChange(isFocused: boolean): void {
super.handleFocusChange(isFocused);
if (isFocused) {
this._webviewKeyboardHandler.didFocus();
} else {
this._webviewKeyboardHandler.didBlur();
}
}
}