fix(vscode): prevent prompt autofocus stealing focus (#8872)

* fix(vscode): prevent prompt autofocus stealing focus

* revert: drop local-bin.ts workaround (no longer needed after main merge)
This commit is contained in:
Marius
2026-04-14 12:19:16 +02:00
committed by GitHub
parent a1bd03d773
commit 52674fffe1
2 changed files with 15 additions and 4 deletions
@@ -145,10 +145,14 @@ export const PermissionDock: Component<{
}
}
// Auto-focus the dock when it appears so keyboard shortcuts work immediately
// Keep keyboard shortcuts when the webview already has focus, but do not
// steal focus from the editor, terminal, or other VS Code surfaces.
createEffect(() => {
void props.request.id
requestAnimationFrame(() => root?.focus())
requestAnimationFrame(() => {
if (!document.hasFocus()) return
root?.focus()
})
})
return (
@@ -245,11 +245,13 @@ export const QuestionDock: Component<{ request: QuestionRequest }> = (props) =>
}
}
// Auto-focus first option when dock appears, tab changes, or editing ends
// Keep keyboard navigation when the webview already has focus, but do not
// steal focus from the editor, terminal, or other VS Code surfaces.
createEffect(() => {
void store.tab
if (store.collapsed || store.editing || confirm()) return
requestAnimationFrame(() => {
if (!document.hasFocus()) return
const btn = root?.querySelector<HTMLButtonElement>("button[data-slot='question-option']:not(:disabled)")
btn?.focus()
})
@@ -376,7 +378,12 @@ export const QuestionDock: Component<{ request: QuestionRequest }> = (props) =>
<Show when={store.editing}>
<form data-slot="custom-input-form" onSubmit={handleCustomSubmit}>
<input
ref={(el) => setTimeout(() => el.focus(), 0)}
ref={(el) => {
setTimeout(() => {
if (!document.hasFocus()) return
el.focus()
}, 0)
}}
type="text"
data-slot="custom-input"
placeholder={language.t("ui.question.custom.placeholder")}