Skip to content

Commit cef5a29

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 cef5a29

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/browser/components/ChatInput/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,16 +497,22 @@ 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();
508513
}
509514
};
515+
window.addEventListener("keyup", handleKeyUp);
510516

511517
window.addEventListener(CUSTOM_EVENTS.TOGGLE_VOICE_INPUT, handleToggle as EventListener);
512518
window.addEventListener("keydown", handleKeyDown);
@@ -862,9 +868,10 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
862868
return;
863869
}
864870

865-
// Space on empty input starts voice recording
871+
// Space on empty input starts voice recording (ignore key repeat from holding)
866872
if (
867873
e.key === " " &&
874+
!e.repeat &&
868875
input.trim() === "" &&
869876
voiceInput.shouldShowUI &&
870877
voiceInput.isApiKeySet &&

0 commit comments

Comments
 (0)