fix(web): thread jump hints no longer stick after a dictation paste (#8189)
Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
c6b8bb8257
commit
5d76653960
2 files changed
+45
-7
No files matched your search
@@ -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());
|
||||
});
|
||||
});
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user