Add robust keyboard keys normalization#546
Conversation
Co-authored-by: liamwhite <[email protected]>
… the global types namespace
5af1511 to
7f8ee9f
Compare
|
This is now ready for rewiew. The big part of this diff is just code comments. |
assets/js/utils/keyboard.ts
Outdated
| 83: 'KeyS', | ||
| 85: 'KeyU', | ||
| 86: 'KeyV', | ||
|
|
There was a problem hiding this comment.
remove all the extra spaces here, they're a bit distracting
There was a problem hiding this comment.
also why not map the remainder of the letter keys as well? why only map what we actually use?
There was a problem hiding this comment.
I don't see any problem with whitespace. It's used to visually group related groups of keys like Arrrow* and Key* keys, plus group keys related to line comments. However, I don't feel like arguing about formatting, so I removed all the spaces.
assets/js/upload.js
Outdated
| // Fetch on "enter" in url field | ||
| remoteUrl.addEventListener('keydown', event => { | ||
| if (event.keyCode === 13) { | ||
| const key = normalizedKeyboardKey(event); |
There was a problem hiding this comment.
unnecessary variable declaration, you could simply have written if (normalizedKeyboardKey(event) === keys.Enter)
assets/js/tagsinput.ts
Outdated
| if (keyCode !== 13 || !ctrlKey) return; | ||
| const { ctrlKey } = event; | ||
|
|
||
| const key = normalizedKeyboardKey(event); |
There was a problem hiding this comment.
unnecessary variable declaration, could've been if (normalizedKeyboardKey(event) !== keys.Enter || !ctrlKey)
assets/js/utils/keyboard.ts
Outdated
| @@ -63,5 +63,9 @@ export const keys = Object.fromEntries(Object.values(keysMapping).map(key => [ke | |||
| */ | |||
| export function normalizedKeyboardKey(event: KeyboardEvent): string { | |||
| const key = asRecord(keysMapping)[event.keyCode]; | |||
There was a problem hiding this comment.
eliminate this variable, use it directly
assets/js/tagsinput.ts
Outdated
| function handleKeyEvent(event: KeyboardEvent) { | ||
| const { keyCode, ctrlKey, shiftKey } = event; | ||
| const { ctrlKey, shiftKey } = event; | ||
|
|
Before you begin
This fixes the numpad enter/arrows for the autocomplete (report on derpibooru), plus refactors the usage of
keyCodein all other places on frontend.Testing
Tested for the regressions in all the shortcuts manually