The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 11:00 UTC
fix(web): stop held dictation when shortcut modifiers are released (#32648)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
lufe committed
Nov 15, 2026 at 03:28 UTC
147de34a93b456769282261cfb4cf0c41c1088a1
2 files changed
+32
-3
apps/web/src/speech/useDictationShortcut.browser.test.tsx
+26
-2
@@ -4,7 +4,8 @@ import { expect, it, vi } from "vite-plus/test";
4
import { render } from "../../test/render";
5
import { useDictationShortcut, type DictationKeyHandlers } from "./useDictationShortcut";
6
7
-vi.mock("../hooks/useSettings", () => ({ useClientSettings: () => "hold" }));
7
+const settings = vi.hoisted(() => ({ mode: "hold" as "hold" | "auto" | "toggle" }));
8
+vi.mock("../hooks/useSettings", () => ({ useClientSettings: () => settings.mode }));
9
10
type ShortcutInput = Parameters<typeof useDictationShortcut>[0];
11
@@ -42,7 +43,8 @@ const press = (repeat = false) =>
43
}),
44
);
45
45
-function actions(available: boolean) {
46
+function actions(available: boolean, mode: typeof settings.mode = "hold") {
47
+ settings.mode = mode;
48
return {
49
available,
50
state: { phase: "idle" as const, error: null, errorAction: null },
@@ -94,6 +96,28 @@ it("finishes a released hold after startup even if the chord was pressed again w
96
expect(speech.stop).toHaveBeenCalledOnce();
97
});
98
99
+it.each([
100
+ { mode: "hold", heldMs: 0, stops: 1 },
101
+ { mode: "auto", heldMs: 300, stops: 1 },
102
+ { mode: "auto", heldMs: 299, stops: 0 },
103
+] as const)(
104
+ "ends a $mode press held $heldMs ms when a chord modifier is released without the letter keyup",
105
+ async ({ mode, heldMs, stops }) => {
106
+ const speech = actions(true, mode);
107
+ using _platform = vi.spyOn(navigator, "platform", "get").mockReturnValue("MacIntel");
108
+ await using _screen = await render(<Probe speech={speech} />);
109
+ using clock = vi.spyOn(performance, "now").mockReturnValue(0);
110
+ press();
111
+ clock.mockReturnValue(heldMs);
112
+ window.dispatchEvent(new KeyboardEvent("keyup", { key: "Alt", code: "AltLeft" }));
113
+ await speech.start.mock.results[0]?.value;
114
+ expect(speech.stop).not.toHaveBeenCalled();
115
+ window.dispatchEvent(new KeyboardEvent("keyup", { key: "Meta", code: "MetaLeft" }));
116
+ await speech.start.mock.results[0]?.value;
117
+ expect(speech.stop).toHaveBeenCalledTimes(stops);
118
+ },
119
+);
120
+
121
const escape = () =>
122
new KeyboardEvent("keydown", { key: "Escape", code: "Escape", bubbles: true, cancelable: true });
123
apps/web/src/speech/useDictationShortcut.ts
+6
-1
@@ -98,6 +98,7 @@ export function useDictationShortcut(input: ShortcutInput) {
98
const pressed = useRef<{
99
generation: number;
100
code: string;
101
+ modifiers: string[];
102
startedAt: number;
103
mode: typeof mode;
104
starting: Promise<void>;
@@ -110,7 +111,10 @@ export function useDictationShortcut(input: ShortcutInput) {
111
shortcutTargets.set(id.current, () => current.current);
112
const finish = (event: KeyboardEvent | null) => {
113
const press = pressed.current;
113
- if (!press || (event && (event.code || event.key) !== press.code)) return;
114
+ if (!press) return;
115
+ // macOS can omit the letter keyup while Command is held; releasing a chord modifier ends it too.
116
+ if (event && (event.code || event.key) !== press.code && !press.modifiers.includes(event.key))
117
+ return;
118
pressed.current = null;
119
if (shouldFinishDictationOnRelease(press.mode, performance.now() - press.startedAt)) {
120
void press.starting.then(() => {
@@ -166,6 +170,7 @@ export function useDictationShortcut(input: ShortcutInput) {
170
pressed.current = {
171
generation: generation.current,
172
code: event.code || event.key,
173
+ modifiers: ["Alt", "Control", "Meta", "Shift"].filter((key) => event.getModifierState(key)),
174
startedAt: performance.now(),
175
mode,
176
starting: speech.start(),