Skip to content
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

[core] fix(HotkeyParser): use e.code to get physical keys #6301

Merged
merged 4 commits into from
Jul 24, 2023

Conversation

adidahiya
Copy link
Contributor

@adidahiya adidahiya commented Jul 24, 2023

Fixes #6257

Checklist

  • Includes tests
  • Update documentation

Changes proposed in this pull request:

Refactor HotkeyParser functions to use event.code instead of event.key in most cases. This property is more reliable than event.key since the latter is prone to changing based on keyboard layout and modifier keys. This change restores the behavior of the hotkey parser (which is responsible for taking a user-requested key combo and generating the appropriate event handler) to that of Blueprint v4.x (it regressed in v5.0 via #6106).

I also updated the docs to move the "Key combo" and "hotkeys tester" sections to the non-deprecated useHotkeys documentation (previously this was only available on the "Hotkeys (legacy)" docs page).

Reviewers should focus on:

No regressions in useHotkeys()

Screenshot

before this change:

2023-07-24 14 21 26

after this change:

2023-07-24 14 21 00

in Blueprint v4.x legacy docs:

2023-07-24 14 21 56

export const SHIFT_KEYS: KeyMap = {
"~": "`",
"!": "1",
Copy link
Contributor Author

@adidahiya adidahiya Jul 24, 2023

Choose a reason for hiding this comment

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

We no longer need the 0-9 digit keys in this mapping because we now handle events with { code: "DigitX" } in a more straightforward way. In a future PR, we can remove this KeyMap entirely by switching to event.code for more keys, but for now I decided to be conservative and make fewer behavioral changes in this PR.

Edit: I added a code comment to reflect this

packages/core/src/components/hotkeys/hotkeyParser.ts Outdated Show resolved Hide resolved
@adidahiya
Copy link
Contributor Author

[core] fix(HotkeyParser): use e.code to get physical keys

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@adidahiya
Copy link
Contributor Author

Fix self-review and lint

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@adidahiya
Copy link
Contributor Author

adidahiya commented Jul 24, 2023

I think there's one more regression compared to v4.x which is worth fixing related to the "space" key.

Currently with this PR:

2023-07-24 14 47 24

On v4.x legacy docs:

2023-07-24 14 48 12

@adidahiya
Copy link
Contributor Author

use e.code for space key

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@adidahiya adidahiya merged commit f5e51ba into develop Jul 24, 2023
@adidahiya adidahiya deleted the ad/fix-hotkey-alt-modifier branch July 24, 2023 19:28
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.

[v5] Hotkeys using alt no longer work as expected
1 participant