mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-29 01:10:04 +02:00
key refactoring
This commit is contained in:
parent
f71aa87b7d
commit
9ddfaf2f18
3 changed files with 80 additions and 83 deletions
|
@ -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);
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue