ignore CapsLock when handling keyDown event (#2373)
* ignore CapsLock when handling keyDown event * fix `this`
This commit is contained in:
parent
68aafe31f9
commit
bf143ed0b8
@ -1518,6 +1518,30 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
|||||||
// Input handling
|
// Input handling
|
||||||
|
|
||||||
private onKeyDown = withBatchedUpdates((event: KeyboardEvent) => {
|
private onKeyDown = withBatchedUpdates((event: KeyboardEvent) => {
|
||||||
|
// normalize `event.key` when CapsLock is pressed #2372
|
||||||
|
if (
|
||||||
|
"Proxy" in window &&
|
||||||
|
((!event.shiftKey && /^[A-Z]$/.test(event.key)) ||
|
||||||
|
(event.shiftKey && /^[a-z]$/.test(event.key)))
|
||||||
|
) {
|
||||||
|
event = new Proxy(event, {
|
||||||
|
get(ev: any, prop) {
|
||||||
|
const value = ev[prop];
|
||||||
|
if (typeof value === "function") {
|
||||||
|
// fix for Proxies hijacking `this`
|
||||||
|
return value.bind(ev);
|
||||||
|
}
|
||||||
|
return prop === "key"
|
||||||
|
? // CapsLock inverts capitalization based on ShiftKey, so invert
|
||||||
|
// it back
|
||||||
|
event.shiftKey
|
||||||
|
? ev.key.toUpperCase()
|
||||||
|
: ev.key.toLowerCase()
|
||||||
|
: value;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// ensures we don't prevent devTools select-element feature
|
// ensures we don't prevent devTools select-element feature
|
||||||
if (event[KEYS.CTRL_OR_CMD] && event.shiftKey && event.key === "C") {
|
if (event[KEYS.CTRL_OR_CMD] && event.shiftKey && event.key === "C") {
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user