key refactoring

This commit is contained in:
Peter Cottle 2012-12-25 17:12:54 -08:00
parent f71aa87b7d
commit 9ddfaf2f18
3 changed files with 80 additions and 83 deletions

View file

@ -11,6 +11,7 @@ var Errors = require('../util/errors');
var Warning = Errors.Warning;
var util = require('../util');
var keyboard = require('../util/keyboard');
var CommandPromptView = Backbone.View.extend({
initialize: function(options) {
@ -109,25 +110,22 @@ var CommandPromptView = Backbone.View.extend({
this.onKey(e);
// we need to capture some of these events.
// WARNING: this key map is not internationalized :(
var keyMap = {
// enter
13: _.bind(function() {
var keyToFuncMap = {
enter: _.bind(function() {
this.submit();
}, this),
// up
38: _.bind(function() {
up: _.bind(function() {
this.commandSelectChange(1);
}, this),
// down
40: _.bind(function() {
down: _.bind(function() {
this.commandSelectChange(-1);
}, this)
};
if (keyMap[e.which] !== undefined) {
var key = keyboard.mapKeycodeToKey(e.which);
if (keyToFuncMap[key] !== undefined) {
e.preventDefault();
keyMap[e.which]();
keyToFuncMap[key]();
this.onKey(e);
}
},