diff --git a/src/command/KeyBindingManager.js b/src/command/KeyBindingManager.js index 387e1605b68..366e3dc1ca9 100644 --- a/src/command/KeyBindingManager.js +++ b/src/command/KeyBindingManager.js @@ -105,7 +105,8 @@ define(function (require, exports, module) { Commands.EDIT_CUT, Commands.EDIT_COPY, Commands.EDIT_PASTE], _reservedShortcuts = ["Ctrl-Z", "Ctrl-Y", "Ctrl-A", "Ctrl-X", "Ctrl-C", "Ctrl-V"], _macReservedShortcuts = ["Cmd-,", "Cmd-H", "Cmd-Alt-H", "Cmd-M", "Cmd-Shift-Z", "Cmd-Q"], - _keyNames = ["Up", "Down", "Left", "Right", "Backspace", "Enter", "Space", "Tab"]; + _keyNames = ["Up", "Down", "Left", "Right", "Backspace", "Enter", "Space", "Tab", + "PageUp", "PageDown", "Home", "End", "Insert", "Delete"]; /** * @private @@ -402,11 +403,16 @@ define(function (require, exports, module) { return null; } - // 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)) { - key = key.toLowerCase().replace(/(^[a-z])/, function (match, p1) { - return p1.toUpperCase(); + // Ensure that the first letter of the key name is in upper case and the rest are + // in lower case. i.e. 'a' => 'A' and 'up' => 'Up' + if (/^[a-z]/i.test(key)) { + key = key.charAt(0).toUpperCase() + key.substr(1).toLowerCase(); + } + + // Also make sure that the second word of PageUp/PageDown has the first letter in upper case. + if (/^Page/.test(key)) { + key = key.replace(/(up|down)$/, function (match, p1) { + return p1.charAt(0).toUpperCase() + p1.substr(1); }); } @@ -504,6 +510,10 @@ define(function (require, exports, module) { key = "Space"; } else if (key === "\b") { key = "Backspace"; + } else if (key === "Help") { + key = "Insert"; + } else if (event.keyCode === KeyEvent.DOM_VK_DELETE) { + key = "Delete"; } else { key = _mapKeycodeToKey(event.keyCode, key); } @@ -1084,7 +1094,7 @@ define(function (require, exports, module) { function _getDisplayKey(key) { var displayKey = "", match = key ? key.match(/(Up|Down|Left|Right|\-)$/i) : null; - if (match) { + if (match && !/Page(Up|Down)/.test(key)) { displayKey = key.substr(0, match.index) + _displayKeyMap[match[0].toLowerCase()]; } return displayKey; diff --git a/test/spec/KeyBindingManager-test-files/invalidKeys.json b/test/spec/KeyBindingManager-test-files/invalidKeys.json index f8e80cff063..2783b0abe2a 100644 --- a/test/spec/KeyBindingManager-test-files/invalidKeys.json +++ b/test/spec/KeyBindingManager-test-files/invalidKeys.json @@ -4,8 +4,7 @@ "command-2": "file.openFolder", "Option-Cmd-Backspace": "view.hideSidebar", "no_modifier_key": "file.openFolder", - "Home": "view.hideSidebar", "ctrl-kk": "file.openFolder", - "cmd-Delete": "view.hideSidebar" + "cmd-Del": "view.hideSidebar" } } \ No newline at end of file diff --git a/test/spec/KeyBindingManager-test.js b/test/spec/KeyBindingManager-test.js index fa49a26e8c1..7d50bd8962f 100644 --- a/test/spec/KeyBindingManager-test.js +++ b/test/spec/KeyBindingManager-test.js @@ -630,10 +630,9 @@ define(function (require, exports, module) { var msgPrefix = Strings.ERROR_INVALID_SHORTCUTS.replace("{0}", ""); expect(message).toMatch(msgPrefix); expect(message).toMatch("command-2"); - expect(message).toMatch("Home"); expect(message).toMatch("Option-Cmd-Backspace"); expect(message).toMatch("ctrl-kk"); - expect(message).toMatch("cmd-Delete"); + expect(message).toMatch("cmd-Del"); return {done: function (callback) { callback(Dialogs.DIALOG_BTN_OK); } }; }); });