| ... | ... | @@ -33,7 +33,12 @@ export function useShortcutModifierState(): ShortcutModifierState { |
| 33 | 33 | const onKeyboardEvent = (event: KeyboardEvent) => { |
| 34 | 34 | setState((current) => shortcutModifierStateAfterKeyboardEvent(current, event)); |
| 35 | 35 | }; |
| 36 | | const onWindowBlur = () => { |
| 36 | // Dictation tools (Wispr Flow) paste with a synthetic ⌘V whose Meta keyup |
| 37 | // never reaches the page, so the tracked state stays "⌘ held" forever and |
| 38 | // the thread jump hints stick on screen. A paste is never jump intent, so |
| 39 | // treat it like a blur and reset. A physically held modifier re-registers |
| 40 | // on the next real key event. |
| 41 | const onResetEvent = () => { |
| 37 | 42 | setState((current) => |
| 38 | 43 | areShortcutModifierStatesEqual(current, EMPTY_SHORTCUT_MODIFIER_STATE) |
| 39 | 44 | ? current |
| ... | ... | @@ -43,11 +48,13 @@ export function useShortcutModifierState(): ShortcutModifierState { |
| 43 | 48 | |
| 44 | 49 | window.addEventListener("keydown", onKeyboardEvent, true); |
| 45 | 50 | window.addEventListener("keyup", onKeyboardEvent, true); |
| 46 | | window.addEventListener("blur", onWindowBlur); |
| 51 | window.addEventListener("paste", onResetEvent, true); |
| 52 | window.addEventListener("blur", onResetEvent); |
| 47 | 53 | return () => { |
| 48 | 54 | window.removeEventListener("keydown", onKeyboardEvent, true); |
| 49 | 55 | window.removeEventListener("keyup", onKeyboardEvent, true); |
| 50 | | window.removeEventListener("blur", onWindowBlur); |
| 56 | window.removeEventListener("paste", onResetEvent, true); |
| 57 | window.removeEventListener("blur", onResetEvent); |
| 51 | 58 | }; |
| 52 | 59 | }, []); |
| 53 | 60 | |
| ... | ... | @@ -84,11 +91,17 @@ export function shortcutModifierStateAfterKeyboardEvent( |
| 84 | 91 | [normalizedModifierKey]: event.type === "keydown", |
| 85 | 92 | }; |
| 86 | 93 | } 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. |
| 87 | 100 | nextState = { |
| 88 | | metaKey: event.metaKey, |
| 89 | | ctrlKey: event.ctrlKey, |
| 90 | | altKey: event.altKey, |
| 91 | | 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, |
| 92 | 105 | }; |
| 93 | 106 | } |
| 94 | 107 | |