Repository navigation
fix(web): reset shortcut modifiers after dictation paste #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
a1f704c
33aa200
a6cb39c
315649a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,10 @@ export function useShortcutModifierState(): ShortcutModifierState { | |
| const onKeyboardEvent = (event: KeyboardEvent) => { | ||
| setState((current) => shortcutModifierStateAfterKeyboardEvent(current, event)); | ||
| }; | ||
| const onWindowBlur = () => { | ||
| // Dictation tools can paste with a synthetic modifier shortcut whose | ||
| // matching keyup never reaches the page. Reset on paste so jump hints do | ||
| // not remain stuck until another modifier event arrives. | ||
| const onResetEvent = () => { | ||
| setState((current) => | ||
| areShortcutModifierStatesEqual(current, EMPTY_SHORTCUT_MODIFIER_STATE) | ||
| ? current | ||
|
|
@@ -43,11 +46,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 +89,13 @@ export function shortcutModifierStateAfterKeyboardEvent( | |
| [normalizedModifierKey]: event.type === "keydown", | ||
| }; | ||
| } else { | ||
| // Non-modifier events can clear stale browser flags, but only a real | ||
| // modifier keydown may mark a modifier as held. | ||
| 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, | ||
|
Comment on lines
+114
to
+115
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
On Windows/Linux layouts where AltGraph is emitted as a Control keydown followed by an Useful? React with 👍 / 👎. |
||
| shiftKey: currentState.shiftKey && event.shiftKey, | ||
| }; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a user performs a normal Ctrl/Cmd+V paste and continues holding Ctrl/Cmd, the capture-phase
pastehandler resets the state even though the modifier remains physically held. The following V keyup or number keydown cannot restore it because non-modifier events now only clear flags, so sidebar jump hints stay hidden until the user releases and presses the modifier again.Useful? React with 👍 / 👎.