Caret/js/keys.js

34 lines
790 B
JavaScript
Raw Normal View History

2013-08-31 20:23:41 +00:00
define(["json!config/keys.json", "command", "editor", "dom2"], function(keyConfig, command, editor) {
2013-08-20 00:53:03 +00:00
/*
2013-09-01 04:21:21 +00:00
Still need to set Sublime keybindings
2013-08-20 00:53:03 +00:00
*/
2013-08-31 20:23:41 +00:00
2013-09-01 04:21:21 +00:00
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
2013-08-31 20:23:41 +00:00
window.on("keydown", function(e) {
var char = String.fromCharCode(e.keyCode);
if (!e.shiftKey) char = char.toLowerCase();
2013-09-01 04:21:21 +00:00
if (e.keyCode in keycodes) {
char = keycodes[e.keyCode];
}
2013-08-31 20:23:41 +00:00
var combo =
e.ctrlKey ? "^-" + char :
e.metaKey ? "M-" + char :
char;
if (combo in keyConfig) {
e.preventDefault();
command.fire(keyConfig[combo]);
}
});
2013-08-20 00:53:03 +00:00
});