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

Commit 46b87ce

Browse files
committed
Merge pull request #10247 from adobe/rlim/more-key-names
Allow more common key names in key bindings (#10233)
2 parents f0b4e98 + ff30488 commit 46b87ce

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/command/KeyBindingManager.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ define(function (require, exports, module) {
105105
Commands.EDIT_CUT, Commands.EDIT_COPY, Commands.EDIT_PASTE],
106106
_reservedShortcuts = ["Ctrl-Z", "Ctrl-Y", "Ctrl-A", "Ctrl-X", "Ctrl-C", "Ctrl-V"],
107107
_macReservedShortcuts = ["Cmd-,", "Cmd-H", "Cmd-Alt-H", "Cmd-M", "Cmd-Shift-Z", "Cmd-Q"],
108-
_keyNames = ["Up", "Down", "Left", "Right", "Backspace", "Enter", "Space", "Tab"];
108+
_keyNames = ["Up", "Down", "Left", "Right", "Backspace", "Enter", "Space", "Tab",
109+
"PageUp", "PageDown", "Home", "End", "Insert", "Delete"];
109110

110111
/**
111112
* @private
@@ -402,11 +403,16 @@ define(function (require, exports, module) {
402403
return null;
403404
}
404405

405-
// Ensure that the first letter of the key name is in upper case.
406-
// i.e. 'a' => 'A' and 'up' => 'Up'
407-
if (/^[a-z]/.test(key)) {
408-
key = key.toLowerCase().replace(/(^[a-z])/, function (match, p1) {
409-
return p1.toUpperCase();
406+
// Ensure that the first letter of the key name is in upper case and the rest are
407+
// in lower case. i.e. 'a' => 'A' and 'up' => 'Up'
408+
if (/^[a-z]/i.test(key)) {
409+
key = key.charAt(0).toUpperCase() + key.substr(1).toLowerCase();
410+
}
411+
412+
// Also make sure that the second word of PageUp/PageDown has the first letter in upper case.
413+
if (/^Page/.test(key)) {
414+
key = key.replace(/(up|down)$/, function (match, p1) {
415+
return p1.charAt(0).toUpperCase() + p1.substr(1);
410416
});
411417
}
412418

@@ -504,6 +510,10 @@ define(function (require, exports, module) {
504510
key = "Space";
505511
} else if (key === "\b") {
506512
key = "Backspace";
513+
} else if (key === "Help") {
514+
key = "Insert";
515+
} else if (event.keyCode === KeyEvent.DOM_VK_DELETE) {
516+
key = "Delete";
507517
} else {
508518
key = _mapKeycodeToKey(event.keyCode, key);
509519
}
@@ -1084,7 +1094,7 @@ define(function (require, exports, module) {
10841094
function _getDisplayKey(key) {
10851095
var displayKey = "",
10861096
match = key ? key.match(/(Up|Down|Left|Right|\-)$/i) : null;
1087-
if (match) {
1097+
if (match && !/Page(Up|Down)/.test(key)) {
10881098
displayKey = key.substr(0, match.index) + _displayKeyMap[match[0].toLowerCase()];
10891099
}
10901100
return displayKey;

test/spec/KeyBindingManager-test-files/invalidKeys.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"command-2": "file.openFolder",
55
"Option-Cmd-Backspace": "view.hideSidebar",
66
"no_modifier_key": "file.openFolder",
7-
"Home": "view.hideSidebar",
87
"ctrl-kk": "file.openFolder",
9-
"cmd-Delete": "view.hideSidebar"
8+
"cmd-Del": "view.hideSidebar"
109
}
1110
}

test/spec/KeyBindingManager-test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,10 +630,9 @@ define(function (require, exports, module) {
630630
var msgPrefix = Strings.ERROR_INVALID_SHORTCUTS.replace("{0}", "");
631631
expect(message).toMatch(msgPrefix);
632632
expect(message).toMatch("command-2");
633-
expect(message).toMatch("Home");
634633
expect(message).toMatch("Option-Cmd-Backspace");
635634
expect(message).toMatch("ctrl-kk");
636-
expect(message).toMatch("cmd-Delete");
635+
expect(message).toMatch("cmd-Del");
637636
return {done: function (callback) { callback(Dialogs.DIALOG_BTN_OK); } };
638637
});
639638
});

0 commit comments

Comments
 (0)