Skip to content

Commit 78c25a3

Browse files
t3dotggclaude
andcommitted
fix(web): ignore poisoned modifier flags from non-modifier keys
Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 7f906ab commit 78c25a3

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

‎apps/web/src/shortcutModifierState.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,29 @@ describe("shortcutModifierState", () => {
110110
shiftKey: false,
111111
});
112112
});
113+
114+
it("ignores poisoned modifier flags on non-modifier keys", () => {
115+
// A dictation paste (synthetic ⌘V) can leave the browser reporting
116+
// metaKey=true on later real key events. Enter to submit must not
117+
// re-mark ⌘ as held.
118+
const state = shortcutModifierStateAfterKeyboardEvent(
119+
emptyState(),
120+
keyboardEventLike("keydown", { key: "Enter", metaKey: true }),
121+
);
122+
expect(state).toEqual(emptyState());
123+
});
124+
125+
it("clears a held modifier when a non-modifier key reports it released", () => {
126+
const heldMeta: ShortcutModifierState = {
127+
metaKey: true,
128+
ctrlKey: false,
129+
altKey: false,
130+
shiftKey: false,
131+
};
132+
const state = shortcutModifierStateAfterKeyboardEvent(
133+
heldMeta,
134+
keyboardEventLike("keydown", { key: "a", metaKey: false }),
135+
);
136+
expect(state).toEqual(emptyState());
137+
});
113138
});

‎apps/web/src/shortcutModifierState.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,17 @@ export function shortcutModifierStateAfterKeyboardEvent(
9191
[normalizedModifierKey]: event.type === "keydown",
9292
};
9393
} else {
94+
// Flags on non-modifier keys may only clear a bit, never set one. After a
95+
// dictation tool's synthetic ⌘V (Wispr Flow), the browser can keep
96+
// reporting metaKey=true on real key events (Enter to submit) until the
97+
// user physically taps ⌘. Trusting that flag would mark ⌘ as held and
98+
// stick the thread jump hints. Setting a bit requires a real modifier
99+
// keydown, handled above.
94100
nextState = {
95-
metaKey: event.metaKey,
96-
ctrlKey: event.ctrlKey,
97-
altKey: event.altKey,
98-
shiftKey: event.shiftKey,
101+
metaKey: currentState.metaKey && event.metaKey,
102+
ctrlKey: currentState.ctrlKey && event.ctrlKey,
103+
altKey: currentState.altKey && event.altKey,
104+
shiftKey: currentState.shiftKey && event.shiftKey,
99105
};
100106
}
101107

0 commit comments

Comments
 (0)