-
Notifications
You must be signed in to change notification settings - Fork 296
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
use event.key for search shortcut #1525
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -236,12 +236,18 @@ var addEventListenerForSearchKeyboard = () => { | |
(event) => { | ||
let input = findSearchInput(); | ||
// toggle on Ctrl+k or ⌘+k | ||
if ((event.ctrlKey || event.metaKey) && event.code == "KeyK") { | ||
if ( | ||
(event.ctrlKey || event.metaKey) && | ||
(/k/i.test(event.key) || event.keyCode === 75) | ||
) { | ||
event.preventDefault(); | ||
toggleSearchField(); | ||
} | ||
// also allow Escape key to hide (but not show) the dynamic search field | ||
else if (document.activeElement === input && event.code == "Escape") { | ||
else if ( | ||
document.activeElement === input && | ||
(/escape/i.test(event.key) || event.keyCode === 27) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above? |
||
) { | ||
toggleSearchField(); | ||
} | ||
}, | ||
|
Oops, something went wrong.
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.
Since this might seem obscure for folks unfamiliar with non-QWERTY layouts, perhaps a comment like this one would be good
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.
why not simply "non en-iso" instead of "DVORAK" ? If I understand correctly this fix is for any keyboard mapping right ?
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.
I don't think it really needs commenting. Most keyboard shortcuts should match the letter (event.key) that would appear in a text editor or input field and not the physical key (event.code) on your keyboard. I know, I know, the terminology is confusing, but that's the way it is.
The exception would be if you're really trying to match the shortcut to a specific physical place on the keyboard. For example, imagine if you were trying to create an app that turns your keyboard into a piano-like musical instrument. Then you would want to map the physical location of keys on the keyboard rather than the letters.
I will add, however, that it's a little fuzzy to me what should happen when apps are internationalized. In a French computer, for example, I think
ctrl + t
opens a new browser tab, even though the word for tab in French, which is "onglet", does not begin with a "t". But it's weird to me that keyboard shortcuts that were chosen because of a first-letter mnemonic in English (for example:ctrl+s
because Save begins with the letter "s") should stay the same across languages.But the bottom line in our case is that if we are showing the keyboard shortcut in the search bar across all languages as
ctrl + k
then we should bind to the letter, not the key.Read event.code and event.key for more explanation.
I think leaving the code without a comment will actually be less confusing than adding a somewhat cryptic comment about key-mapping because standard practice is to use
event.key
for most keyboard shortcuts.