Skip to content

Commit 92e31f3

Browse files
committed
fix: global keybinds during recording work regardless of focus
- Add window-level keydown listener active only during recording - Space and Escape work even if overlay button loses focus - Removed redundant local onKeyDown and auto-focus from button
1 parent 91c65e7 commit 92e31f3

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/browser/components/ChatInput/index.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,23 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
500500
window.removeEventListener(CUSTOM_EVENTS.TOGGLE_VOICE_INPUT, handler as EventListener);
501501
}, [voiceInput, setToast]);
502502

503+
// Global keybinds during recording (work regardless of focus)
504+
useEffect(() => {
505+
if (voiceInput.state !== "recording") return;
506+
507+
const handler = (e: KeyboardEvent) => {
508+
if (e.key === " ") {
509+
e.preventDefault();
510+
voiceInput.stop({ send: true });
511+
} else if (e.key === "Escape") {
512+
e.preventDefault();
513+
voiceInput.cancel();
514+
}
515+
};
516+
window.addEventListener("keydown", handler);
517+
return () => window.removeEventListener("keydown", handler);
518+
}, [voiceInput]);
519+
503520
// Auto-focus chat input when workspace changes (workspace only)
504521
const workspaceIdForFocus = variant === "workspace" ? props.workspaceId : null;
505522
useEffect(() => {
@@ -992,17 +1009,7 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
9921009
{voiceInput.state !== "idle" ? (
9931010
<button
9941011
type="button"
995-
ref={(el) => el?.focus()}
9961012
onClick={voiceInput.state === "recording" ? voiceInput.toggle : undefined}
997-
onKeyDown={(e) => {
998-
if (e.key === " " && voiceInput.state === "recording") {
999-
e.preventDefault();
1000-
voiceInput.stop({ send: true });
1001-
} else if (e.key === "Escape" && voiceInput.state === "recording") {
1002-
e.preventDefault();
1003-
voiceInput.cancel();
1004-
}
1005-
}}
10061013
disabled={voiceInput.state === "transcribing"}
10071014
className={cn(
10081015
"mb-1 flex min-h-[60px] w-full items-center justify-center gap-3 rounded-md border px-4 py-4 transition-all focus:outline-none",

0 commit comments

Comments
 (0)