aboutsummaryrefslogtreecommitdiffstats
path: root/commands.js
diff options
context:
space:
mode:
authorilya2010-02-26 22:47:55 -0800
committerilya2010-02-26 22:47:55 -0800
commitf4a0f8b79678fd8d67f1ccb140f838df04a7313a (patch)
treed5cd331b89a6a5a0a388bb8261628abfb2de5c14 /commands.js
parent7c2cb40b4ee49935910c6e0308df55aaf906256f (diff)
downloadvimium-f4a0f8b79678fd8d67f1ccb140f838df04a7313a.tar.bz2
Key Mapping - Initial support. Basics work.
Diffstat (limited to 'commands.js')
-rw-r--r--commands.js36
1 files changed, 31 insertions, 5 deletions
diff --git a/commands.js b/commands.js
index a2e53a18..d7c8b12a 100644
--- a/commands.js
+++ b/commands.js
@@ -11,8 +11,7 @@ function addCommand(command, description, isBackgroundCommand) {
availableCommands[command] = { description: description, isBackgroundCommand: isBackgroundCommand };
}
-function mapKeyToCommand(key, command)
-{
+function mapKeyToCommand(key, command) {
if (!availableCommands[command])
{
console.log(command, "doesn't exist!");
@@ -22,6 +21,36 @@ function mapKeyToCommand(key, command)
keyToCommandRegistry[key] = { command: command, isBackgroundCommand: availableCommands[command].isBackgroundCommand };
}
+function unmapKey(key) { delete keyToCommandRegistry[key]; }
+
+function parseCustomKeyMappings(customKeyMappings) {
+ lines = customKeyMappings.split("\n");
+
+ for (var i = 0; i < lines.length; i++) {
+ line = lines[i].split(" "); // TODO(ilya): Support all whitespace.
+ if (line.length < 2) { continue }
+
+ var lineCommand = line[0];
+ var key = line[1];
+
+ if (lineCommand == "map") {
+ if (line.length != 3) { continue }
+
+ var vimiumCommand = line[2];
+
+ if (!availableCommands[vimiumCommand]) { continue }
+
+ console.log("Mapping", key, "to", vimiumCommand);
+ mapKeyToCommand(key, vimiumCommand);
+ }
+ else if (lineCommand == "unmap") {
+ console.log("Unmapping", key);
+ unmapKey(key);
+ }
+ }
+}
+
+// TODO(ilya): Fill in these descriptions.
addCommand('scrollDown', '');
addCommand('scrollUp', '');
addCommand('scrollLeft', '');
@@ -36,9 +65,6 @@ addCommand('reload', '');
addCommand('toggleViewSource', '');
addCommand('enterInsertMode', '');
addCommand('goBack', '');
-addCommand('goBack', '');
-addCommand('goForward', '');
-addCommand('goForward', '');
addCommand('goForward', '');
addCommand('zoomIn', '');
addCommand('zoomOut', '');