From 52674fffe109e1c329c1734aef76be988c01dafa Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 14 Apr 2026 12:19:16 +0200 Subject: [PATCH] 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) --- .../webview-ui/src/components/chat/PermissionDock.tsx | 8 ++++++-- .../webview-ui/src/components/chat/QuestionDock.tsx | 11 +++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/kilo-vscode/webview-ui/src/components/chat/PermissionDock.tsx b/packages/kilo-vscode/webview-ui/src/components/chat/PermissionDock.tsx index d03615c254..bf20c69fde 100644 --- a/packages/kilo-vscode/webview-ui/src/components/chat/PermissionDock.tsx +++ b/packages/kilo-vscode/webview-ui/src/components/chat/PermissionDock.tsx @@ -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 ( diff --git a/packages/kilo-vscode/webview-ui/src/components/chat/QuestionDock.tsx b/packages/kilo-vscode/webview-ui/src/components/chat/QuestionDock.tsx index 6d033517c1..6300796229 100644 --- a/packages/kilo-vscode/webview-ui/src/components/chat/QuestionDock.tsx +++ b/packages/kilo-vscode/webview-ui/src/components/chat/QuestionDock.tsx @@ -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("button[data-slot='question-option']:not(:disabled)") btn?.focus() }) @@ -376,7 +378,12 @@ export const QuestionDock: Component<{ request: QuestionRequest }> = (props) =>
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")}