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

Commit 6c8d32e

Browse files
committed
Merge pull request #1583 from couzteau/couzteau-issue1241
Couzteau issue1241
2 parents 3f889e4 + 951247c commit 6c8d32e

File tree

10 files changed

+195
-35
lines changed

10 files changed

+195
-35
lines changed

src/command/KeyBindingManager.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ define(function (require, exports, module) {
3434
require("utils/Global");
3535

3636
var CommandManager = require("command/CommandManager"),
37+
KeyEvent = require("utils/KeyEvent"),
3738
Strings = require("strings");
3839

3940
/**
@@ -182,27 +183,27 @@ define(function (require, exports, module) {
182183
**/
183184
function _mapKeycodeToKey(keycode, key) {
184185
switch (keycode) {
185-
case 186:
186+
case KeyEvent.DOM_VK_SEMICOLON:
186187
return ";";
187-
case 187:
188+
case KeyEvent.DOM_VK_EQUALS:
188189
return "=";
189-
case 188:
190+
case KeyEvent.DOM_VK_COMMA:
190191
return ",";
191-
case 189:
192+
case KeyEvent.DOM_VK_DASH:
192193
return "-";
193-
case 190:
194+
case KeyEvent.DOM_VK_PERIOD:
194195
return ".";
195-
case 191:
196+
case KeyEvent.DOM_VK_SLASH:
196197
return "/";
197-
case 192:
198+
case KeyEvent.DOM_VK_BACK_QUOTE:
198199
return "`";
199-
case 219:
200+
case KeyEvent.DOM_VK_OPEN_BRACKET:
200201
return "[";
201-
case 220:
202+
case KeyEvent.DOM_VK_BACK_SLASH:
202203
return "\\";
203-
case 221:
204+
case KeyEvent.DOM_VK_CLOSE_BRACKET:
204205
return "]";
205-
case 222:
206+
case KeyEvent.DOM_VK_QUOTE:
206207
return "'";
207208
default:
208209
return key;

src/document/DocumentCommandHandlers.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ define(function (require, exports, module) {
4545
Dialogs = require("widgets/Dialogs"),
4646
Strings = require("strings"),
4747
PreferencesManager = require("preferences/PreferencesManager"),
48-
PerfUtils = require("utils/PerfUtils");
48+
PerfUtils = require("utils/PerfUtils"),
49+
KeyEvent = require("utils/KeyEvent");
4950

5051
/**
5152
* Handlers for commands related to document handling (opening, saving, etc.)
@@ -746,7 +747,7 @@ define(function (require, exports, module) {
746747
* @param {jQueryEvent} event Key-up event
747748
*/
748749
function detectDocumentNavEnd(event) {
749-
if (event.keyCode === 17) { // Ctrl key
750+
if (event.keyCode === KeyEvent.DOM_VK_CONTROL) { // Ctrl key
750751
DocumentManager.finalizeDocumentNavigation();
751752

752753
_addedNavKeyHandler = false;

src/editor/CodeHintManager.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ define(function (require, exports, module) {
3434
StringUtils = require("utils/StringUtils"),
3535
EditorManager = require("editor/EditorManager"),
3636
PopUpManager = require("widgets/PopUpManager"),
37-
ViewUtils = require("utils/ViewUtils");
37+
ViewUtils = require("utils/ViewUtils"),
38+
KeyEvent = require("utils/KeyEvent");
3839

3940

4041
var hintProviders = [],
@@ -178,20 +179,20 @@ define(function (require, exports, module) {
178179

179180
// Up arrow, down arrow and enter key are always handled here
180181
if (event.type !== "keypress" &&
181-
(keyCode === 38 || keyCode === 40 || keyCode === 13 ||
182-
keyCode === 33 || keyCode === 34)) {
182+
(keyCode === KeyEvent.DOM_VK_UP || keyCode === KeyEvent.DOM_VK_DOWN || keyCode === KeyEvent.DOM_VK_RETURN ||
183+
keyCode === KeyEvent.DOM_VK_PAGE_UP || keyCode === KeyEvent.DOM_VK_PAGE_DOWN)) {
183184

184185
if (event.type === "keydown") {
185-
if (keyCode === 38) {
186+
if (keyCode === KeyEvent.DOM_VK_UP) {
186187
// Up arrow
187188
this.setSelectedIndex(this.selectedIndex - 1);
188-
} else if (keyCode === 40) {
189+
} else if (keyCode === KeyEvent.DOM_VK_DOWN) {
189190
// Down arrow
190191
this.setSelectedIndex(this.selectedIndex + 1);
191-
} else if (keyCode === 33) {
192+
} else if (keyCode === KeyEvent.DOM_VK_PAGE_UP) {
192193
// Page Up
193194
this.setSelectedIndex(this.selectedIndex - this.getItemsPerPage());
194-
} else if (keyCode === 34) {
195+
} else if (keyCode === KeyEvent.DOM_VK_PAGE_DOWN) {
195196
// Page Down
196197
this.setSelectedIndex(this.selectedIndex + this.getItemsPerPage());
197198
} else {

src/editor/InlineWidget.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ define(function (require, exports, module) {
2929
"use strict";
3030

3131
// Load dependent modules
32-
var EditorManager = require("editor/EditorManager");
32+
var EditorManager = require("editor/EditorManager"),
33+
KeyEvent = require("utils/KeyEvent");
3334

3435
/**
3536
* @constructor
@@ -45,7 +46,7 @@ define(function (require, exports, module) {
4546
.append("<div class='shadow bottom' />");
4647

4748
this.$htmlContent.on("keydown", function (e) {
48-
if (e.keyCode === 27) {
49+
if (e.keyCode === KeyEvent.DOM_VK_ESCAPE) {
4950
self.close();
5051
e.stopImmediatePropagation();
5152
}

src/project/ProjectManager.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ define(function (require, exports, module) {
5959
PerfUtils = require("utils/PerfUtils"),
6060
ViewUtils = require("utils/ViewUtils"),
6161
FileUtils = require("file/FileUtils"),
62-
Urls = require("i18n!nls/urls");
62+
Urls = require("i18n!nls/urls"),
63+
KeyEvent = require("utils/KeyEvent");
6364

6465
/**
6566
* @private
@@ -926,7 +927,8 @@ define(function (require, exports, module) {
926927

927928
$renameInput.on("keydown", function (event) {
928929
// Listen for escape key on keydown, so we can remove the node in the create.jstree handler above
929-
if (event.keyCode === 27) {
930+
if (event.keyCode === KeyEvent.DOM_VK_ESCAPE) {
931+
930932
escapeKeyPressed = true;
931933
}
932934
});

src/search/FindInFiles.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ define(function (require, exports, module) {
4949
StringUtils = require("utils/StringUtils"),
5050
DocumentManager = require("document/DocumentManager"),
5151
EditorManager = require("editor/EditorManager"),
52-
FileIndexManager = require("project/FileIndexManager");
52+
FileIndexManager = require("project/FileIndexManager"),
53+
KeyEvent = require("utils/KeyEvent");
54+
5355

5456
var FIND_IN_FILES_MAX = 100;
5557

@@ -108,13 +110,13 @@ define(function (require, exports, module) {
108110
$searchField.get(0).select();
109111

110112
$searchField.bind("keydown", function (event) {
111-
if (event.keyCode === 13 || event.keyCode === 27) { // Enter/Return key or Esc key
113+
if (event.keyCode === KeyEvent.DOM_VK_RETURN || event.keyCode === KeyEvent.DOM_VK_ESCAPE) { // Enter/Return key or Esc key
112114
event.stopPropagation();
113115
event.preventDefault();
114116

115117
var query = $searchField.val();
116118

117-
if (event.keyCode === 27) {
119+
if (event.keyCode === KeyEvent.DOM_VK_ESCAPE) {
118120
query = null;
119121
}
120122

src/utils/KeyEvent.js

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
24+
25+
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
26+
/*global define */
27+
28+
/**
29+
* Utilities module to provide constants for keyCodes
30+
*/
31+
define({
32+
DOM_VK_CANCEL: 3,
33+
DOM_VK_HELP: 6,
34+
DOM_VK_BACK_SPACE: 8,
35+
DOM_VK_TAB: 9,
36+
DOM_VK_CLEAR: 12,
37+
DOM_VK_RETURN: 13,
38+
DOM_VK_ENTER: 14,
39+
DOM_VK_SHIFT: 16,
40+
DOM_VK_CONTROL: 17,
41+
DOM_VK_ALT: 18,
42+
DOM_VK_PAUSE: 19,
43+
DOM_VK_CAPS_LOCK: 20,
44+
DOM_VK_ESCAPE: 27,
45+
DOM_VK_SPACE: 32,
46+
DOM_VK_PAGE_UP: 33,
47+
DOM_VK_PAGE_DOWN: 34,
48+
DOM_VK_END: 35,
49+
DOM_VK_HOME: 36,
50+
DOM_VK_LEFT: 37,
51+
DOM_VK_UP: 38,
52+
DOM_VK_RIGHT: 39,
53+
DOM_VK_DOWN: 40,
54+
DOM_VK_PRINTSCREEN: 44,
55+
DOM_VK_INSERT: 45,
56+
DOM_VK_DELETE: 46,
57+
DOM_VK_0: 48,
58+
DOM_VK_1: 49,
59+
DOM_VK_2: 50,
60+
DOM_VK_3: 51,
61+
DOM_VK_4: 52,
62+
DOM_VK_5: 53,
63+
DOM_VK_6: 54,
64+
DOM_VK_7: 55,
65+
DOM_VK_8: 56,
66+
DOM_VK_9: 57,
67+
DOM_VK_A: 65,
68+
DOM_VK_B: 66,
69+
DOM_VK_C: 67,
70+
DOM_VK_D: 68,
71+
DOM_VK_E: 69,
72+
DOM_VK_F: 70,
73+
DOM_VK_G: 71,
74+
DOM_VK_H: 72,
75+
DOM_VK_I: 73,
76+
DOM_VK_J: 74,
77+
DOM_VK_K: 75,
78+
DOM_VK_L: 76,
79+
DOM_VK_M: 77,
80+
DOM_VK_N: 78,
81+
DOM_VK_O: 79,
82+
DOM_VK_P: 80,
83+
DOM_VK_Q: 81,
84+
DOM_VK_R: 82,
85+
DOM_VK_S: 83,
86+
DOM_VK_T: 84,
87+
DOM_VK_U: 85,
88+
DOM_VK_V: 86,
89+
DOM_VK_W: 87,
90+
DOM_VK_X: 88,
91+
DOM_VK_Y: 89,
92+
DOM_VK_Z: 90,
93+
DOM_VK_CONTEXT_MENU: 93,
94+
DOM_VK_NUMPAD0: 96,
95+
DOM_VK_NUMPAD1: 97,
96+
DOM_VK_NUMPAD2: 98,
97+
DOM_VK_NUMPAD3: 99,
98+
DOM_VK_NUMPAD4: 100,
99+
DOM_VK_NUMPAD5: 101,
100+
DOM_VK_NUMPAD6: 102,
101+
DOM_VK_NUMPAD7: 103,
102+
DOM_VK_NUMPAD8: 104,
103+
DOM_VK_NUMPAD9: 105,
104+
DOM_VK_MULTIPLY: 106,
105+
DOM_VK_ADD: 107,
106+
DOM_VK_SEPARATOR: 108,
107+
DOM_VK_SUBTRACT: 109,
108+
DOM_VK_DECIMAL: 110,
109+
DOM_VK_DIVIDE: 111,
110+
DOM_VK_F1: 112,
111+
DOM_VK_F2: 113,
112+
DOM_VK_F3: 114,
113+
DOM_VK_F4: 115,
114+
DOM_VK_F5: 116,
115+
DOM_VK_F6: 117,
116+
DOM_VK_F7: 118,
117+
DOM_VK_F8: 119,
118+
DOM_VK_F9: 120,
119+
DOM_VK_F10: 121,
120+
DOM_VK_F11: 122,
121+
DOM_VK_F12: 123,
122+
DOM_VK_F13: 124,
123+
DOM_VK_F14: 125,
124+
DOM_VK_F15: 126,
125+
DOM_VK_F16: 127,
126+
DOM_VK_F17: 128,
127+
DOM_VK_F18: 129,
128+
DOM_VK_F19: 130,
129+
DOM_VK_F20: 131,
130+
DOM_VK_F21: 132,
131+
DOM_VK_F22: 133,
132+
DOM_VK_F23: 134,
133+
DOM_VK_F24: 135,
134+
DOM_VK_NUM_LOCK: 144,
135+
DOM_VK_SCROLL_LOCK: 145,
136+
DOM_VK_SEMICOLON: 186,
137+
DOM_VK_EQUALS: 187,
138+
DOM_VK_COMMA: 188,
139+
DOM_VK_DASH: 189,
140+
DOM_VK_PERIOD: 190,
141+
DOM_VK_SLASH: 191,
142+
DOM_VK_BACK_QUOTE: 192,
143+
DOM_VK_OPEN_BRACKET: 219,
144+
DOM_VK_BACK_SLASH: 220,
145+
DOM_VK_CLOSE_BRACKET: 221,
146+
DOM_VK_QUOTE: 222,
147+
DOM_VK_META: 224
148+
149+
});

src/widgets/Dialogs.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ define(function (require, exports, module) {
3333

3434
require("utils/Global");
3535

36-
var KeyBindingManager = require("command/KeyBindingManager");
36+
var KeyBindingManager = require("command/KeyBindingManager"),
37+
KeyEvent = require("utils/KeyEvent");
3738

3839
var DIALOG_BTN_CANCEL = "cancel",
3940
DIALOG_BTN_OK = "ok",
@@ -66,12 +67,12 @@ define(function (require, exports, module) {
6667
buttonId = null,
6768
which = String.fromCharCode(e.which);
6869

69-
if (e.which === 13) {
70+
if (e.which === KeyEvent.DOM_VK_RETURN) {
7071
// Click primary button
7172
if (primaryBtn) {
7273
buttonId = primaryBtn.attr("data-button-id");
7374
}
74-
} else if (e.which === 32) {
75+
} else if (e.which === KeyEvent.DOM_VK_SPACE) {
7576
// Space bar on focused button
7677
this.find(".dialog-button:focus").click();
7778
} else if (brackets.platform === "mac") {
@@ -81,7 +82,7 @@ define(function (require, exports, module) {
8182
buttonId = DIALOG_BTN_DONTSAVE;
8283
}
8384
// FIXME (issue #418) CMD+. Cancel swallowed by native shell
84-
} else if (e.metaKey && (e.which === 190)) {
85+
} else if (e.metaKey && (e.which === KeyEvent.DOM_VK_PERIOD)) {
8586
buttonId = DIALOG_BTN_CANCEL;
8687
}
8788
} else { // if (brackets.platform === "win") {

src/widgets/PopUpManager.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@
2323

2424

2525
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
26-
/*global define, $, brackets, window */
26+
/*global define, window, $, brackets */
2727

2828
/**
2929
* Utilities for managing pop-ups.
3030
*/
3131
define(function (require, exports, module) {
3232
"use strict";
3333

34-
var EditorManager = require("editor/EditorManager");
34+
var EditorManager = require("editor/EditorManager"),
35+
KeyEvent = require("utils/KeyEvent");
3536

3637
var _popUps = [];
3738

@@ -82,7 +83,7 @@ define(function (require, exports, module) {
8283
}
8384

8485
function _keydownCaptureListener(keyEvent) {
85-
if (keyEvent.keyCode !== 27) { // escape key
86+
if (keyEvent.keyCode !== KeyEvent.DOM_VK_ESCAPE) { // escape key
8687
return;
8788
}
8889

test/spec/CodeHint-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ define(function (require, exports, module) {
3131
var HTMLUtils = require("language/HTMLUtils"),
3232
SpecRunnerUtils = require("spec/SpecRunnerUtils"),
3333
Editor = require("editor/Editor").Editor,
34+
KeyEvent = require("utils/KeyEvent"),
3435
EditorManager, // loaded from brackets.test
3536
CodeHintManager;
3637

@@ -103,7 +104,7 @@ define(function (require, exports, module) {
103104
// simulate Ctrl+space keystroke to invoke code hints menu
104105
runs(function () {
105106
var e = $.Event("keydown");
106-
e.keyCode = 32; // spacebar key
107+
e.keyCode = KeyEvent.DOM_VK_SPACE; // spacebar key
107108
e.ctrlKey = true;
108109

109110
editor = EditorManager.getCurrentFullEditor();

0 commit comments

Comments
 (0)