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

Commit

Permalink
Merge pull request #1583 from couzteau/couzteau-issue1241
Browse files Browse the repository at this point in the history
Couzteau issue1241
  • Loading branch information
jasonsanjose committed Sep 12, 2012
2 parents 3f889e4 + 951247c commit 6c8d32e
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 35 deletions.
23 changes: 12 additions & 11 deletions src/command/KeyBindingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ define(function (require, exports, module) {
require("utils/Global");

var CommandManager = require("command/CommandManager"),
KeyEvent = require("utils/KeyEvent"),
Strings = require("strings");

/**
Expand Down Expand Up @@ -182,27 +183,27 @@ define(function (require, exports, module) {
**/
function _mapKeycodeToKey(keycode, key) {
switch (keycode) {
case 186:
case KeyEvent.DOM_VK_SEMICOLON:
return ";";
case 187:
case KeyEvent.DOM_VK_EQUALS:
return "=";
case 188:
case KeyEvent.DOM_VK_COMMA:
return ",";
case 189:
case KeyEvent.DOM_VK_DASH:
return "-";
case 190:
case KeyEvent.DOM_VK_PERIOD:
return ".";
case 191:
case KeyEvent.DOM_VK_SLASH:
return "/";
case 192:
case KeyEvent.DOM_VK_BACK_QUOTE:
return "`";
case 219:
case KeyEvent.DOM_VK_OPEN_BRACKET:
return "[";
case 220:
case KeyEvent.DOM_VK_BACK_SLASH:
return "\\";
case 221:
case KeyEvent.DOM_VK_CLOSE_BRACKET:
return "]";
case 222:
case KeyEvent.DOM_VK_QUOTE:
return "'";
default:
return key;
Expand Down
5 changes: 3 additions & 2 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ define(function (require, exports, module) {
Dialogs = require("widgets/Dialogs"),
Strings = require("strings"),
PreferencesManager = require("preferences/PreferencesManager"),
PerfUtils = require("utils/PerfUtils");
PerfUtils = require("utils/PerfUtils"),
KeyEvent = require("utils/KeyEvent");

/**
* Handlers for commands related to document handling (opening, saving, etc.)
Expand Down Expand Up @@ -746,7 +747,7 @@ define(function (require, exports, module) {
* @param {jQueryEvent} event Key-up event
*/
function detectDocumentNavEnd(event) {
if (event.keyCode === 17) { // Ctrl key
if (event.keyCode === KeyEvent.DOM_VK_CONTROL) { // Ctrl key
DocumentManager.finalizeDocumentNavigation();

_addedNavKeyHandler = false;
Expand Down
15 changes: 8 additions & 7 deletions src/editor/CodeHintManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ define(function (require, exports, module) {
StringUtils = require("utils/StringUtils"),
EditorManager = require("editor/EditorManager"),
PopUpManager = require("widgets/PopUpManager"),
ViewUtils = require("utils/ViewUtils");
ViewUtils = require("utils/ViewUtils"),
KeyEvent = require("utils/KeyEvent");


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

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

if (event.type === "keydown") {
if (keyCode === 38) {
if (keyCode === KeyEvent.DOM_VK_UP) {
// Up arrow
this.setSelectedIndex(this.selectedIndex - 1);
} else if (keyCode === 40) {
} else if (keyCode === KeyEvent.DOM_VK_DOWN) {
// Down arrow
this.setSelectedIndex(this.selectedIndex + 1);
} else if (keyCode === 33) {
} else if (keyCode === KeyEvent.DOM_VK_PAGE_UP) {
// Page Up
this.setSelectedIndex(this.selectedIndex - this.getItemsPerPage());
} else if (keyCode === 34) {
} else if (keyCode === KeyEvent.DOM_VK_PAGE_DOWN) {
// Page Down
this.setSelectedIndex(this.selectedIndex + this.getItemsPerPage());
} else {
Expand Down
5 changes: 3 additions & 2 deletions src/editor/InlineWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ define(function (require, exports, module) {
"use strict";

// Load dependent modules
var EditorManager = require("editor/EditorManager");
var EditorManager = require("editor/EditorManager"),
KeyEvent = require("utils/KeyEvent");

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

this.$htmlContent.on("keydown", function (e) {
if (e.keyCode === 27) {
if (e.keyCode === KeyEvent.DOM_VK_ESCAPE) {
self.close();
e.stopImmediatePropagation();
}
Expand Down
6 changes: 4 additions & 2 deletions src/project/ProjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ define(function (require, exports, module) {
PerfUtils = require("utils/PerfUtils"),
ViewUtils = require("utils/ViewUtils"),
FileUtils = require("file/FileUtils"),
Urls = require("i18n!nls/urls");
Urls = require("i18n!nls/urls"),
KeyEvent = require("utils/KeyEvent");

/**
* @private
Expand Down Expand Up @@ -926,7 +927,8 @@ define(function (require, exports, module) {

$renameInput.on("keydown", function (event) {
// Listen for escape key on keydown, so we can remove the node in the create.jstree handler above
if (event.keyCode === 27) {
if (event.keyCode === KeyEvent.DOM_VK_ESCAPE) {

escapeKeyPressed = true;
}
});
Expand Down
8 changes: 5 additions & 3 deletions src/search/FindInFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ define(function (require, exports, module) {
StringUtils = require("utils/StringUtils"),
DocumentManager = require("document/DocumentManager"),
EditorManager = require("editor/EditorManager"),
FileIndexManager = require("project/FileIndexManager");
FileIndexManager = require("project/FileIndexManager"),
KeyEvent = require("utils/KeyEvent");


var FIND_IN_FILES_MAX = 100;

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

$searchField.bind("keydown", function (event) {
if (event.keyCode === 13 || event.keyCode === 27) { // Enter/Return key or Esc key
if (event.keyCode === KeyEvent.DOM_VK_RETURN || event.keyCode === KeyEvent.DOM_VK_ESCAPE) { // Enter/Return key or Esc key
event.stopPropagation();
event.preventDefault();

var query = $searchField.val();

if (event.keyCode === 27) {
if (event.keyCode === KeyEvent.DOM_VK_ESCAPE) {
query = null;
}

Expand Down
149 changes: 149 additions & 0 deletions src/utils/KeyEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define */

/**
* Utilities module to provide constants for keyCodes
*/
define({
DOM_VK_CANCEL: 3,
DOM_VK_HELP: 6,
DOM_VK_BACK_SPACE: 8,
DOM_VK_TAB: 9,
DOM_VK_CLEAR: 12,
DOM_VK_RETURN: 13,
DOM_VK_ENTER: 14,
DOM_VK_SHIFT: 16,
DOM_VK_CONTROL: 17,
DOM_VK_ALT: 18,
DOM_VK_PAUSE: 19,
DOM_VK_CAPS_LOCK: 20,
DOM_VK_ESCAPE: 27,
DOM_VK_SPACE: 32,
DOM_VK_PAGE_UP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F5: 116,
DOM_VK_F6: 117,
DOM_VK_F7: 118,
DOM_VK_F8: 119,
DOM_VK_F9: 120,
DOM_VK_F10: 121,
DOM_VK_F11: 122,
DOM_VK_F12: 123,
DOM_VK_F13: 124,
DOM_VK_F14: 125,
DOM_VK_F15: 126,
DOM_VK_F16: 127,
DOM_VK_F17: 128,
DOM_VK_F18: 129,
DOM_VK_F19: 130,
DOM_VK_F20: 131,
DOM_VK_F21: 132,
DOM_VK_F22: 133,
DOM_VK_F23: 134,
DOM_VK_F24: 135,
DOM_VK_NUM_LOCK: 144,
DOM_VK_SCROLL_LOCK: 145,
DOM_VK_SEMICOLON: 186,
DOM_VK_EQUALS: 187,
DOM_VK_COMMA: 188,
DOM_VK_DASH: 189,
DOM_VK_PERIOD: 190,
DOM_VK_SLASH: 191,
DOM_VK_BACK_QUOTE: 192,
DOM_VK_OPEN_BRACKET: 219,
DOM_VK_BACK_SLASH: 220,
DOM_VK_CLOSE_BRACKET: 221,
DOM_VK_QUOTE: 222,
DOM_VK_META: 224

});
9 changes: 5 additions & 4 deletions src/widgets/Dialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ define(function (require, exports, module) {

require("utils/Global");

var KeyBindingManager = require("command/KeyBindingManager");
var KeyBindingManager = require("command/KeyBindingManager"),
KeyEvent = require("utils/KeyEvent");

var DIALOG_BTN_CANCEL = "cancel",
DIALOG_BTN_OK = "ok",
Expand Down Expand Up @@ -66,12 +67,12 @@ define(function (require, exports, module) {
buttonId = null,
which = String.fromCharCode(e.which);

if (e.which === 13) {
if (e.which === KeyEvent.DOM_VK_RETURN) {
// Click primary button
if (primaryBtn) {
buttonId = primaryBtn.attr("data-button-id");
}
} else if (e.which === 32) {
} else if (e.which === KeyEvent.DOM_VK_SPACE) {
// Space bar on focused button
this.find(".dialog-button:focus").click();
} else if (brackets.platform === "mac") {
Expand All @@ -81,7 +82,7 @@ define(function (require, exports, module) {
buttonId = DIALOG_BTN_DONTSAVE;
}
// FIXME (issue #418) CMD+. Cancel swallowed by native shell
} else if (e.metaKey && (e.which === 190)) {
} else if (e.metaKey && (e.which === KeyEvent.DOM_VK_PERIOD)) {
buttonId = DIALOG_BTN_CANCEL;
}
} else { // if (brackets.platform === "win") {
Expand Down
7 changes: 4 additions & 3 deletions src/widgets/PopUpManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, window */
/*global define, window, $, brackets */

/**
* Utilities for managing pop-ups.
*/
define(function (require, exports, module) {
"use strict";

var EditorManager = require("editor/EditorManager");
var EditorManager = require("editor/EditorManager"),
KeyEvent = require("utils/KeyEvent");

var _popUps = [];

Expand Down Expand Up @@ -82,7 +83,7 @@ define(function (require, exports, module) {
}

function _keydownCaptureListener(keyEvent) {
if (keyEvent.keyCode !== 27) { // escape key
if (keyEvent.keyCode !== KeyEvent.DOM_VK_ESCAPE) { // escape key
return;
}

Expand Down
3 changes: 2 additions & 1 deletion test/spec/CodeHint-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ define(function (require, exports, module) {
var HTMLUtils = require("language/HTMLUtils"),
SpecRunnerUtils = require("spec/SpecRunnerUtils"),
Editor = require("editor/Editor").Editor,
KeyEvent = require("utils/KeyEvent"),
EditorManager, // loaded from brackets.test
CodeHintManager;

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

editor = EditorManager.getCurrentFullEditor();
Expand Down

0 comments on commit 6c8d32e

Please sign in to comment.