diff --git a/src/vs/platform/browserView/electron-main/browserViewMainService.ts b/src/vs/platform/browserView/electron-main/browserViewMainService.ts index 7d95fe8d3d3..0e28a487e6a 100644 --- a/src/vs/platform/browserView/electron-main/browserViewMainService.ts +++ b/src/vs/platform/browserView/electron-main/browserViewMainService.ts @@ -169,8 +169,8 @@ export class BrowserViewMainService extends Disposable implements IBrowserViewMa // Request the workbench to open the editor this.windowsMainService.sendToFocused('vscode:runAction', { - id: 'vscode.open', - args: [BrowserViewUri.forUrl(url, targetId)] + id: '_workbench.open', + args: [BrowserViewUri.forUrl(url, targetId), [undefined, { preserveFocus: true }], undefined] }); return view; diff --git a/src/vs/workbench/contrib/browserView/electron-browser/browserEditor.ts b/src/vs/workbench/contrib/browserView/electron-browser/browserEditor.ts index 0cd292267d5..364df91d6f2 100644 --- a/src/vs/workbench/contrib/browserView/electron-browser/browserEditor.ts +++ b/src/vs/workbench/contrib/browserView/electron-browser/browserEditor.ts @@ -391,7 +391,8 @@ export class BrowserEditor extends EditorPane { this._inputDisposables.clear(); // Resolve the browser view model from the input - this._model = await input.resolve(); + const model = await input.resolve(); + this._model = model; if (token.isCancellationRequested || this.input !== input) { return; } @@ -425,12 +426,16 @@ export class BrowserEditor extends EditorPane { }); this.setBackgroundImage(this._model.screenshot); - if (context.newInGroup) { - if (this._model.url) { - this._browserContainer.focus(); - } else { - this.focusUrlInput(); - } + if (!options?.preserveFocus) { + setTimeout(() => { + if (this._model === model) { + if (this._model.url) { + this._browserContainer.focus(); + } else { + this.focusUrlInput(); + } + } + }, 0); } // Start / stop screenshots when the model visibility changes diff --git a/src/vs/workbench/contrib/browserView/electron-browser/browserFindWidget.ts b/src/vs/workbench/contrib/browserView/electron-browser/browserFindWidget.ts index ea918e0428f..aec2add429b 100644 --- a/src/vs/workbench/contrib/browserView/electron-browser/browserFindWidget.ts +++ b/src/vs/workbench/contrib/browserView/electron-browser/browserFindWidget.ts @@ -105,6 +105,7 @@ export class BrowserFindWidget extends SimpleFindWidget { // Stop find and clear highlights in the browser view this._model?.stopFindInPage(true); + this._model?.focus(); this._lastFindResult = undefined; this._hasFoundMatch = false; }