Skip to content

Commit a86270d

Browse files
fix(web): Escape and tool keys work as soon as preview annotation starts
Starting annotation left keyboard focus in the app, because main's WebContents.focus() cannot move the embedder's DOM focus into a webview guest. Escape and the V/R/D/E tool keys did nothing until the user clicked inside the page. Focus the tab's <webview> element when the pick starts; the existing restore puts focus back when annotation ends. Fixes #32970 AI-assisted; verified with the tests and tools listed above.
1 parent 5c6f2f1 commit a86270d

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎apps/web/src/components/preview/PreviewView.tsx‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,18 @@ function ServerTabFileNotShown(props: {
146146
);
147147
}
148148

149-
function focusPreviewPage(runtimeTabId: string) {
150-
const active = document.activeElement;
151-
if (active && active !== document.body && !active.closest("[data-preview-panel-mode]")) return;
149+
function focusPreviewWebview(runtimeTabId: string) {
152150
document
153151
.querySelector<HTMLElement>(`[data-preview-viewport="${CSS.escape(runtimeTabId)}"] webview`)
154152
?.focus();
155153
}
156154

155+
function focusPreviewPage(runtimeTabId: string) {
156+
const active = document.activeElement;
157+
if (active && active !== document.body && !active.closest("[data-preview-panel-mode]")) return;
158+
focusPreviewWebview(runtimeTabId);
159+
}
160+
157161
export function PreviewView({
158162
threadRef,
159163
tabId: requestedTabId,
@@ -816,6 +820,9 @@ export function PreviewView({
816820
readEnvironmentScope(threadRef.environmentId, AuthOrchestrationOperateScope),
817821
);
818822
if (pickRequest.cancelled) return;
823+
// Main's WebContents.focus() cannot move the embedder's DOM focus into a guest, so key
824+
// presses would stay in the app; only focusing the <webview> element hands them to the page.
825+
focusPreviewWebview(runtimeTabId);
819826
const result = await bridge.pickElement(runtimeTabId, voice);
820827
if (!result || pickRequest.cancelled) return;
821828
// The accepted pick must survive further clicks, tab changes, and unmount; stop cancellation here.

0 commit comments

Comments
 (0)