Skip to content

Add robust keyboard keys normalization#546

Merged
Meow merged 12 commits intophilomena-dev:masterfrom
MareStare:fix/keypad-enter
May 7, 2025
Merged

Add robust keyboard keys normalization#546
Meow merged 12 commits intophilomena-dev:masterfrom
MareStare:fix/keypad-enter

Conversation

@MareStare
Copy link
Contributor

@MareStare MareStare commented May 1, 2025

Before you begin

  • I understand my contributions may be rejected for any reason
  • I understand my contributions are for the benefit of Derpibooru and/or the Philomena software
  • I understand my contributions are licensed under the GNU AGPLv3
  • I understand all of the above

This fixes the numpad enter/arrows for the autocomplete (report on derpibooru), plus refactors the usage of keyCode in all other places on frontend.

Testing

Tested for the regressions in all the shortcuts manually

@MareStare MareStare force-pushed the fix/keypad-enter branch from 5af1511 to 7f8ee9f Compare May 2, 2025 14:04
@MareStare MareStare requested a review from liamwhite May 2, 2025 14:08
@MareStare MareStare marked this pull request as ready for review May 2, 2025 14:08
@MareStare
Copy link
Contributor Author

MareStare commented May 2, 2025

This is now ready for rewiew. The big part of this diff is just code comments.

83: 'KeyS',
85: 'KeyU',
86: 'KeyV',

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove all the extra spaces here, they're a bit distracting

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also why not map the remainder of the letter keys as well? why only map what we actually use?

Copy link
Contributor Author

@MareStare MareStare May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

// Fetch on "enter" in url field
remoteUrl.addEventListener('keydown', event => {
if (event.keyCode === 13) {
const key = normalizedKeyboardKey(event);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary variable declaration, you could simply have written if (normalizedKeyboardKey(event) === keys.Enter)

if (keyCode !== 13 || !ctrlKey) return;
const { ctrlKey } = event;

const key = normalizedKeyboardKey(event);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary variable declaration, could've been if (normalizedKeyboardKey(event) !== keys.Enter || !ctrlKey)

@@ -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];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eliminate this variable, use it directly

function handleKeyEvent(event: KeyboardEvent) {
const { keyCode, ctrlKey, shiftKey } = event;
const { ctrlKey, shiftKey } = event;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eliminate this empty line

@Meow Meow merged commit a73ed13 into philomena-dev:master May 7, 2025
6 checks passed
@Meow Meow added this to the 1.2 milestone May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants