2013-09-03 15:47:59 +00:00
|
|
|
define(["settings!keys", "command", "editor", "dom2"], function(Settings, 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 = {
|
2013-09-05 15:11:19 +00:00
|
|
|
9: "TAB",
|
|
|
|
13: "RETURN",
|
|
|
|
32: "SPACE",
|
|
|
|
37: "LEFT",
|
|
|
|
39: "RIGHT",
|
|
|
|
38: "UP",
|
|
|
|
40: "DOWN"
|
2013-09-03 15:47:59 +00:00
|
|
|
};
|
2013-09-01 04:21:21 +00:00
|
|
|
|
|
|
|
//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);
|
2013-09-01 04:21:21 +00:00
|
|
|
if (e.keyCode in keycodes) {
|
|
|
|
char = keycodes[e.keyCode];
|
|
|
|
}
|
2013-09-05 15:11:19 +00:00
|
|
|
if (!e.shiftKey) char = char.toLowerCase();
|
2013-08-31 20:23:41 +00:00
|
|
|
var combo =
|
|
|
|
e.ctrlKey ? "^-" + char :
|
|
|
|
e.metaKey ? "M-" + char :
|
|
|
|
char;
|
2013-09-03 15:47:59 +00:00
|
|
|
var keyConfig = Settings.get("keys");
|
2013-08-31 20:23:41 +00:00
|
|
|
if (combo in keyConfig) {
|
|
|
|
e.preventDefault();
|
2013-09-05 15:11:19 +00:00
|
|
|
var action = keyConfig[combo];
|
|
|
|
if (typeof action == "string") {
|
|
|
|
action = {
|
|
|
|
command: action
|
|
|
|
};
|
|
|
|
}
|
|
|
|
command.fire(action.command, action.argument);
|
2013-08-31 20:23:41 +00:00
|
|
|
}
|
|
|
|
});
|
2013-08-20 00:53:03 +00:00
|
|
|
|
|
|
|
});
|