Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(web): thread jump hints no longer stick after a dictation paste (#8189)

Theo Browne5d7665396083
diff --git a/apps/web/src/shortcutModifierState.test.ts b/apps/web/src/shortcutModifierState.test.ts
index cb62d45bc..4ef4b3b6b 100644
--- a/apps/web/src/shortcutModifierState.test.ts
+++ b/apps/web/src/shortcutModifierState.test.ts
@@ -110,4 +110,29 @@ describe("shortcutModifierState", () => {
shiftKey: false,
});
});
+
+ it("ignores poisoned modifier flags on non-modifier keys", () => {
+ // A dictation paste (synthetic ⌘V) can leave the browser reporting
+ // metaKey=true on later real key events. Enter to submit must not
+ // re-mark ⌘ as held.
+ const state = shortcutModifierStateAfterKeyboardEvent(
+ emptyState(),
+ keyboardEventLike("keydown", { key: "Enter", metaKey: true }),
+ );
+ expect(state).toEqual(emptyState());
+ });
+
+ it("clears a held modifier when a non-modifier key reports it released", () => {
+ const heldMeta: ShortcutModifierState = {
+ metaKey: true,
+ ctrlKey: false,
+ altKey: false,
+ shiftKey: false,
+ };
+ const state = shortcutModifierStateAfterKeyboardEvent(
+ heldMeta,
+ keyboardEventLike("keydown", { key: "a", metaKey: false }),
+ );
+ expect(state).toEqual(emptyState());
+ });
});
diff --git a/apps/web/src/shortcutModifierState.ts b/apps/web/src/shortcutModifierState.ts
index a56a1a129..3abeeaa3e 100644
--- a/apps/web/src/shortcutModifierState.ts
+++ b/apps/web/src/shortcutModifierState.ts
@@ -33,7 +33,12 @@ export function useShortcutModifierState(): ShortcutModifierState {
const onKeyboardEvent = (event: KeyboardEvent) => {
setState((current) => shortcutModifierStateAfterKeyboardEvent(current, event));
};
- const onWindowBlur = () => {
+ // Dictation tools (Wispr Flow) paste with a synthetic ⌘V whose Meta keyup
+ // never reaches the page, so the tracked state stays "⌘ held" forever and
+ // the thread jump hints stick on screen. A paste is never jump intent, so
+ // treat it like a blur and reset. A physically held modifier re-registers
+ // on the next real key event.
+ const onResetEvent = () => {
setState((current) =>
areShortcutModifierStatesEqual(current, EMPTY_SHORTCUT_MODIFIER_STATE)
? current
@@ -43,11 +48,13 @@ export function useShortcutModifierState(): ShortcutModifierState {
window.addEventListener("keydown", onKeyboardEvent, true);
window.addEventListener("keyup", onKeyboardEvent, true);
- window.addEventListener("blur", onWindowBlur);
+ window.addEventListener("paste", onResetEvent, true);
+ window.addEventListener("blur", onResetEvent);
return () => {
window.removeEventListener("keydown", onKeyboardEvent, true);
window.removeEventListener("keyup", onKeyboardEvent, true);
- window.removeEventListener("blur", onWindowBlur);
+ window.removeEventListener("paste", onResetEvent, true);
+ window.removeEventListener("blur", onResetEvent);
};
}, []);
@@ -84,11 +91,17 @@ export function shortcutModifierStateAfterKeyboardEvent(
[normalizedModifierKey]: event.type === "keydown",
};
} else {
+ // Flags on non-modifier keys may only clear a bit, never set one. After a
+ // dictation tool's synthetic ⌘V (Wispr Flow), the browser can keep
+ // reporting metaKey=true on real key events (Enter to submit) until the
+ // user physically taps ⌘. Trusting that flag would mark ⌘ as held and
+ // stick the thread jump hints. Setting a bit requires a real modifier
+ // keydown, handled above.
nextState = {
- metaKey: event.metaKey,
- ctrlKey: event.ctrlKey,
- altKey: event.altKey,
- shiftKey: event.shiftKey,
+ metaKey: currentState.metaKey && event.metaKey,
+ ctrlKey: currentState.ctrlKey && event.ctrlKey,
+ altKey: currentState.altKey && event.altKey,
+ shiftKey: currentState.shiftKey && event.shiftKey,
};
}