Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Allow more common key names in key bindings (#10233) #10247

Merged
merged 4 commits into from
Jan 8, 2015

Conversation

RaymondLim
Copy link
Contributor

This fixes issue #10233.

key = key.replace(/(up|down)$/, function (match, p1) {
return p1.charAt(0).toUpperCase() + p1.substr(1);
});
}
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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).

@redmunds
Copy link
Contributor

This KeyBindingManager unit test needs to be fixed:

"should show an error when parsing invalid shortcuts"

Error: Expected 'These shortcuts are invalid: <ul class='dialog-list'><li>command-2</li><li>Option-Cmd-Backspace</li><li>no_modifier_key</li><li>ctrl-kk</li><li>cmd-Delete</li></ul>' to match 'Home'.
    at new jasmine.ExpectationResult (file:///C:/Users/redmunds/dev/github/brackets-shell/Release/dev/test/thirdparty/jasmine-core/jasmine.js:114:32)
    at null.toMatch (file:///C:/Users/redmunds/dev/github/brackets-shell/Release/dev/test/thirdparty/jasmine-core/jasmine.js:1235:29)
    at Object.<anonymous> (file:///C:/Users/redmunds/dev/github/brackets-shell/Release/dev/test/spec/KeyBindingManager-test.js:633:41)
    at Object.spyObj (file:///C:/Users/redmunds/dev/github/brackets-shell/Release/dev/test/thirdparty/jasmine-core/jasmine.js:413:24)
    at file:///C:/Users/redmunds/dev/github/brackets-shell/Release/dev/src/command/KeyBindingManager.js:1017:21
    at Object.context.execCb (file:///C:/Users/redmunds/dev/github/brackets-shell/Release/dev/src/thirdparty/requirejs/require.js:1658:33)
    at Object.Module.check (file:///C:/Users/redmunds/dev/github/brackets-shell/Release/dev/src/thirdparty/requirejs/require.js:874:51)
    at Object.Module.enable (file:///C:/Users/redmunds/dev/github/brackets-shell/Release/dev/src/thirdparty/requirejs/require.js:1151:22)
    at Object.Module.init (file:///C:/Users/redmunds/dev/github/brackets-shell/Release/dev/src/thirdparty/requirejs/require.js:782:26)
    at file:///C:/Users/redmunds/dev/github/brackets-shell/Release/dev/src/thirdparty/requirejs/require.js:1424:36

@redmunds
Copy link
Contributor

Done with review.

@RaymondLim
Copy link
Contributor Author

@redmunds Thanks for reviewing and catching the unit test failure. I just pushed the unit test fix and this is ready for another review.

@@ -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)) {
Copy link
Contributor

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 ä.

Copy link
Contributor Author

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.

Copy link
Contributor

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();
}

@redmunds redmunds changed the title Allow more common key names in key bindings. Allow more common key names in key bindings (#10233) Jan 7, 2015
@redmunds
Copy link
Contributor

redmunds commented Jan 8, 2015

Looks good. Merging.

redmunds added a commit that referenced this pull request Jan 8, 2015
Allow more common key names in key bindings (#10233)
@redmunds redmunds merged commit 46b87ce into master Jan 8, 2015
@redmunds redmunds deleted the rlim/more-key-names branch January 8, 2015 17:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants