Skip to content

handle webview focus on webviewWorkbenchService #139050

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ export class WebviewEditorService extends Disposable implements IWebviewWorkbenc
this._iconManager = this._register(this._instantiationService.createInstance(WebviewIconManager));

this._register(_editorService.onDidActiveEditorChange(() => {
this.updateActiveWebview();
this.updateActiveWebview(true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isFocused == true doesn't make sense to me here. I think the parameter either needs to be renamed or we should fix this another way

}));

// The user may have switched focus between two sides of a diff editor
this._register(_webviewService.onDidChangeActiveWebview(() => {
this.updateActiveWebview();
this._register(_webviewService.onDidChangeActiveWebview(newActiveWebview => {
this.updateActiveWebview(!!newActiveWebview);
}));

this.updateActiveWebview();
this.updateActiveWebview(true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also seems incorrect to assume a webview is focused on init

}

get iconManager() {
Expand All @@ -197,7 +197,7 @@ export class WebviewEditorService extends Disposable implements IWebviewWorkbenc
private readonly _onDidChangeActiveWebviewEditor = this._register(new Emitter<WebviewInput | undefined>());
public readonly onDidChangeActiveWebviewEditor = this._onDidChangeActiveWebviewEditor.event;

private updateActiveWebview() {
private updateActiveWebview(isFocused: Boolean) {
const activeInput = this._editorService.activeEditor;

let newActiveWebview: WebviewInput | undefined;
Expand All @@ -213,7 +213,12 @@ export class WebviewEditorService extends Disposable implements IWebviewWorkbenc

if (newActiveWebview !== this._activeWebview) {
this._activeWebview = newActiveWebview;
}

if (isFocused || newActiveWebview !== this._activeWebview) {
this._onDidChangeActiveWebviewEditor.fire(newActiveWebview);
} else {
this._onDidChangeActiveWebviewEditor.fire(undefined);
}
}

Expand Down