Skip to content

Commit

Permalink
fix: prevent keyboard listener crash when browser autocompletes text …
Browse files Browse the repository at this point in the history
…inputs
  • Loading branch information
verekia committed May 26, 2024
1 parent 47b99a0 commit edddaf2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/core/src/listeners/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ export const mountKeyboardListener = ({ onKeyUp, onKeyDown }: KeyboardListenerPr
const upHandler = (e: KeyboardEvent) => {
keyboardStore.setState(s => {
const newKeyboard: Mutable<Keyboard> = { ...s, codes: { ...s.codes }, keys: { ...s.keys } }
delete newKeyboard.codes[e.code]
delete newKeyboard.keys[e.key]
delete newKeyboard.keys[e.key.toUpperCase()]
delete newKeyboard.keys[e.key.toLowerCase()]
if (e.code) {
delete newKeyboard.codes[e.code]
}
if (e.key) {
delete newKeyboard.keys[e.key]
delete newKeyboard.keys[e.key.toUpperCase()]
delete newKeyboard.keys[e.key.toLowerCase()]
}
delete newKeyboard.keys.Dead
newKeyboard.ctrl = e.ctrlKey
newKeyboard.shift = e.shiftKey
Expand Down

0 comments on commit edddaf2

Please sign in to comment.