Skip to content

Commit b370461

Browse files
committed
fix: require space release before send during voice recording
Holding space was triggering start→send in rapid succession. Now tracks whether space is held and requires release before allowing send action.
1 parent 38d0f2c commit b370461

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/browser/components/ChatInput/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,16 +497,25 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
497497
};
498498

499499
// Global keybinds only active during recording
500+
// Track if space is held to prevent start→send on hold
501+
let spaceHeld = true; // Assume held since recording just started via space
502+
const handleKeyUp = (e: KeyboardEvent) => {
503+
if (e.key === " ") spaceHeld = false;
504+
};
500505
const handleKeyDown = (e: KeyboardEvent) => {
501506
if (voiceInput.state !== "recording") return;
502-
if (e.key === " ") {
507+
if (e.key === " " && !spaceHeld) {
503508
e.preventDefault();
504509
voiceInput.stop({ send: true });
505510
} else if (e.key === "Escape") {
506511
e.preventDefault();
507512
voiceInput.cancel();
513+
} else if (matchesKeybind(e, KEYBINDS.TOGGLE_VOICE_INPUT)) {
514+
e.preventDefault();
515+
voiceInput.stop();
508516
}
509517
};
518+
window.addEventListener("keyup", handleKeyUp);
510519

511520
window.addEventListener(CUSTOM_EVENTS.TOGGLE_VOICE_INPUT, handleToggle as EventListener);
512521
window.addEventListener("keydown", handleKeyDown);
@@ -862,9 +871,10 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
862871
return;
863872
}
864873

865-
// Space on empty input starts voice recording
874+
// Space on empty input starts voice recording (ignore key repeat from holding)
866875
if (
867876
e.key === " " &&
877+
!e.repeat &&
868878
input.trim() === "" &&
869879
voiceInput.shouldShowUI &&
870880
voiceInput.isApiKeySet &&

0 commit comments

Comments
 (0)