-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(slash): do not handle / + shift/alt, support for ascii keyboard #2599
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| declare global { | ||
| /** | ||
| * https://developer.mozilla.org/en-US/docs/Web/API/KeyboardLayoutMap | ||
| */ | ||
| interface KeyboardLayoutMap { | ||
| get(key: string): string | undefined; | ||
| has(key: string): boolean; | ||
| size: number; | ||
| entries(): IterableIterator<[string, string]>; | ||
| keys(): IterableIterator<string>; | ||
| values(): IterableIterator<string>; | ||
| forEach(callbackfn: (value: string, key: string, map: KeyboardLayoutMap) => void, thisArg?: unknown): void; | ||
| } | ||
|
|
||
| /** | ||
| * The getLayoutMap() method of the Keyboard interface returns a Promise | ||
| * that resolves with an instance of KeyboardLayoutMap which is a map-like object | ||
| * with functions for retrieving the strings associated with specific physical keys. | ||
| * https://developer.mozilla.org/en-US/docs/Web/API/Keyboard/getLayoutMap | ||
| */ | ||
| interface Keyboard { | ||
| getLayoutMap(): Promise<KeyboardLayoutMap>; | ||
| } | ||
|
|
||
| interface Navigator { | ||
| /** | ||
| * Keyboard API. Not supported by Firefox and Safari. | ||
| */ | ||
| keyboard?: Keyboard; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns real layout-related keyboard key for a given key code. | ||
| * For example, for "Slash" it will return "/" on US keyboard and "-" on Spanish keyboard. | ||
| * | ||
| * Works with Keyboard API which is not supported by Firefox and Safari. So fallback is used for these browsers. | ||
| * | ||
| * @see https://developer.mozilla.org/en-US/docs/Web/API/Keyboard | ||
| * @param code - {@link https://www.w3.org/TR/uievents-code/#key-alphanumeric-writing-system} | ||
| * @param fallback - fallback value to be returned if Keyboard API is not supported (Safari, Firefox) | ||
| */ | ||
| export async function getKeyboardKeyForCode(code: string, fallback: string): Promise<string> { | ||
| const keyboard = navigator.keyboard; | ||
|
|
||
| if (!keyboard) { | ||
| return fallback; | ||
| } | ||
|
|
||
| const map = await keyboard.getLayoutMap(); | ||
| const key = map.get(code); | ||
|
|
||
| return key || fallback; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Control or meta keys
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CMD+/andCTRL+/open Block Tunes — this behaviour stays the same.Problem was in
Shift+/andAlt+/— Toolbox won't be shown now, since "key" will be "?" or "÷" — we don't need to check Shift or Alt separately. Previously we checkedkeyCodewhich is the same for those chars.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, okay. Shift is a bit weird for me here, because in some layouts I can't type / without shift.