-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Allow more common key names in key bindings (#10233) #10247
Conversation
key = key.replace(/(up|down)$/, function (match, p1) { | ||
return p1.charAt(0).toUpperCase() + p1.substr(1); | ||
}); | ||
} |
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.
Do you really need this? Seems like a case-sensitive search of _keyNames
list will catch this.
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.
Yes, we do need this since we don't want the case-sensitive search of _keyNames
list to catch a case-insensitive-matching key
and reject it by returning null
. We also need the exactly matching case for the shell code to correctly assign the corresponding accelerator.
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.
It looks like this changes Pageup
to be PageUp
and Pagedown
to be PageDown
, but pageup
or pagedown
are not changed. Is that correct?
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.
The if
block above this already takes care of the first letter of all key names and here we're only taking care of the two key names that have the second word.
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 tried creating shortcuts with PAGEUP
and PAGEDOWN
and they fail. Seems weird that case doesn't need to be exact, but only some case are accepted. Is that the intention?
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.
@redmunds Good catch! This if
statement is assuming that the other if
block above it has been executed and all letters except the first one are already in lower case. So the culprit is in /^[a-z]/.test(key)
where we should be testing with i
flag. That is, we've already had a bug that has nothing to do with this case conversion (as in UP
not converted to Up
).
This KeyBindingManager unit test needs to be fixed: "should show an error when parsing invalid shortcuts"
|
Done with review. |
@redmunds Thanks for reviewing and catching the unit test failure. I just pushed the unit test fix and this is ready for another review. |
…first letter is already in upper case.
@@ -404,12 +405,19 @@ define(function (require, exports, module) { | |||
|
|||
// Ensure that the first letter of the key name is in upper case. | |||
// i.e. 'a' => 'A' and 'up' => 'Up' | |||
if (/^[a-z]/.test(key)) { | |||
if (/^[a-z]/i.test(key)) { |
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 don't you just do it like this?
key = key.charAt(0).toUpperCase() + key.substr(1).toLowerCase();
This probably also resolves problems with umlauts like ä
.
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.
Because I don't want to convert non-English alphabet like ä
to uppercase. Also to exclude other punctuation and numeric characters.
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.
.toUpperCase()
will no-op on non-letters.
And if you really need to check for valid English letters, you can still do it like this:
if (/^[a-z]/i.test(key)) {
key = key.charAt(0).toUpperCase() + key.substr(1).toLowerCase();
}
Looks good. Merging. |
Allow more common key names in key bindings (#10233)
This fixes issue #10233.