Skip to content

Commit 4fad82e

Browse files
committed
feat: add Simple Browser: Focus Content command
Adds a new command that moves focus directly to the browser content/webview, bypassing the URL bar. This improves accessibility for screen reader users who need a more efficient way to navigate into the browser content. Fixes #305717
1 parent 1da74cc commit 4fad82e

5 files changed

Lines changed: 25 additions & 0 deletions

File tree

extensions/simple-browser/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
],
2525
"activationEvents": [
2626
"onCommand:simpleBrowser.api.open",
27+
"onCommand:simpleBrowser.focusContent",
2728
"onOpenExternalUri:http",
2829
"onOpenExternalUri:https",
2930
"onWebviewPanel:simpleBrowser.view"
@@ -40,13 +41,22 @@
4041
"command": "simpleBrowser.show",
4142
"title": "Show",
4243
"category": "Simple Browser"
44+
},
45+
{
46+
"command": "simpleBrowser.focusContent",
47+
"title": "%command.focusContent.title%",
48+
"category": "Simple Browser"
4349
}
4450
],
4551
"menus": {
4652
"commandPalette": [
4753
{
4854
"command": "simpleBrowser.show",
4955
"when": "isWeb"
56+
},
57+
{
58+
"command": "simpleBrowser.focusContent",
59+
"when": "activeWebviewPanelId == 'simpleBrowser.view'"
5060
}
5161
]
5262
},
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"displayName": "Simple Browser",
33
"description": "A very basic built-in webview for displaying web content.",
4+
"command.focusContent.title": "Focus Content",
45
"configuration.focusLockIndicator.enabled.description": "Enable/disable the floating indicator that shows when focused in the simple browser."
56
}

extensions/simple-browser/src/extension.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ declare class URL {
1414

1515
const openApiCommand = 'simpleBrowser.api.open';
1616
const showCommand = 'simpleBrowser.show';
17+
const focusContentCommand = 'simpleBrowser.focusContent';
1718
const integratedBrowserCommand = 'workbench.action.browser.open';
1819

1920
const enabledHosts = new Set<string>([
@@ -75,6 +76,10 @@ export function activate(context: vscode.ExtensionContext) {
7576
}
7677
}));
7778

79+
context.subscriptions.push(vscode.commands.registerCommand(focusContentCommand, () => {
80+
manager.focusContent();
81+
}));
82+
7883
context.subscriptions.push(vscode.commands.registerCommand(openApiCommand, async (url: vscode.Uri, showOptions?: {
7984
preserveFocus?: boolean;
8085
viewColumn: vscode.ViewColumn;

extensions/simple-browser/src/simpleBrowserManager.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export class SimpleBrowserManager {
3838
this._activeView ??= view;
3939
}
4040

41+
public focusContent(): void {
42+
this._activeView?.focusContent();
43+
}
44+
4145
private registerWebviewListeners(view: SimpleBrowserView) {
4246
view.onDispose(() => {
4347
if (this._activeView === view) {

extensions/simple-browser/src/simpleBrowserView.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ export class SimpleBrowserView extends Disposable {
110110
this._webviewPanel.reveal(options?.viewColumn, options?.preserveFocus);
111111
}
112112

113+
public focusContent() {
114+
this._webviewPanel.reveal(undefined, false);
115+
this._webviewPanel.webview.postMessage({ type: 'focus' });
116+
}
117+
113118
private getHtml(url: string) {
114119
const configuration = vscode.workspace.getConfiguration('simpleBrowser');
115120

0 commit comments

Comments
 (0)