Caret/js/keys.js
2013-08-31 21:21:21 -07:00

34 lines
No EOL
790 B
JavaScript

define(["json!config/keys.json", "command", "editor", "dom2"], function(keyConfig, command, editor) {
/*
Still need to set Sublime keybindings
*/
var keycodes = {
9: "tab",
13: "return",
32: "space",
37: "left",
39: "right",
38: "up",
40: "down"
}
//we have to listen on keydown, because keypress will get caught by the window manager
window.on("keydown", function(e) {
var char = String.fromCharCode(e.keyCode);
if (!e.shiftKey) char = char.toLowerCase();
if (e.keyCode in keycodes) {
char = keycodes[e.keyCode];
}
var combo =
e.ctrlKey ? "^-" + char :
e.metaKey ? "M-" + char :
char;
if (combo in keyConfig) {
e.preventDefault();
command.fire(keyConfig[combo]);
}
});
});