| ... | @@ -33,7 +33,12 @@ export function useShortcutModifierState(): ShortcutModifierState { | ... | @@ -33,7 +33,12 @@ export function useShortcutModifierState(): ShortcutModifierState { |
| 33 | const onKeyboardEvent = (event: KeyboardEvent) => { | 33 | const onKeyboardEvent = (event: KeyboardEvent) => { |
| 34 | setState((current) => shortcutModifierStateAfterKeyboardEvent(current, event)); | 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 | setState((current) => | 42 | setState((current) => |
| 38 | areShortcutModifierStatesEqual(current, EMPTY_SHORTCUT_MODIFIER_STATE) | 43 | areShortcutModifierStatesEqual(current, EMPTY_SHORTCUT_MODIFIER_STATE) |
| 39 | ? current | 44 | ? current |
| ... | @@ -43,11 +48,13 @@ export function useShortcutModifierState(): ShortcutModifierState { | ... | @@ -43,11 +48,13 @@ export function useShortcutModifierState(): ShortcutModifierState { |
| 43 | | 48 | |
| 44 | window.addEventListener("keydown", onKeyboardEvent, true); | 49 | window.addEventListener("keydown", onKeyboardEvent, true); |
| 45 | window.addEventListener("keyup", onKeyboardEvent, true); | 50 | window.addEventListener("keyup", onKeyboardEvent, true); |
| 46 | window.addEventListener("blur", onWindowBlur); | 51 | window.addEventListener("paste", onResetEvent, true); |
| | 52 | window.addEventListener("blur", onResetEvent); |
| 47 | return () => { | 53 | return () => { |
| 48 | window.removeEventListener("keydown", onKeyboardEvent, true); | 54 | window.removeEventListener("keydown", onKeyboardEvent, true); |
| 49 | window.removeEventListener("keyup", onKeyboardEvent, true); | 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,11 +91,17 @@ export function shortcutModifierStateAfterKeyboardEvent( |
| 84 | [normalizedModifierKey]: event.type === "keydown", | 91 | [normalizedModifierKey]: event.type === "keydown", |
| 85 | }; | 92 | }; |
| 86 | } else { | 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 | nextState = { | 100 | nextState = { |
| 88 | metaKey: event.metaKey, | 101 | metaKey: currentState.metaKey && event.metaKey, |
| 89 | ctrlKey: event.ctrlKey, | 102 | ctrlKey: currentState.ctrlKey && event.ctrlKey, |
| 90 | altKey: event.altKey, | 103 | altKey: currentState.altKey && event.altKey, |
| 91 | shiftKey: event.shiftKey, | 104 | shiftKey: currentState.shiftKey && event.shiftKey, |
| 92 | }; | 105 | }; |
| 93 | } | 106 | } |
| 94 | | 107 | |