diff options
| author | ilya | 2009-12-30 14:30:07 -0800 |
|---|---|---|
| committer | ilya | 2009-12-30 14:30:07 -0800 |
| commit | a4ef4933a112f45fedabbc1d8dfb24cc653e7c32 (patch) | |
| tree | 54a66edb54739fafaf1007f268258826d145fc1b | |
| parent | b1506439e172f81f8233b17489fc6f0190eef95b (diff) | |
| download | vimium-a4ef4933a112f45fedabbc1d8dfb24cc653e7c32.tar.bz2 | |
Add logic to the background page to calculate the keys that will complete a valid command given the current key queue.
| -rw-r--r-- | background_page.html | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/background_page.html b/background_page.html index 0213eebc..132b9c4a 100644 --- a/background_page.html +++ b/background_page.html @@ -4,6 +4,7 @@ var tabQueue = {}; // windowId -> Array var keyQueue = ""; // Queue of keys typed var validFirstKeys = {}; + var oneKeyCommands = []; var defaultSettings = { scrollStepSize: 60 }; @@ -246,6 +247,12 @@ keyToCommandRegistry['d'] = removeTab; keyToCommandRegistry['u'] = restoreTab; + function getActualKeyStrokeLength(key) { + if (key.slice(0, 3) == "<c-" && key[key.length - 1] == ">") + return 1; + else + return key.length; + } function populateValidFirstKeys() { for (var key in keyToCommandRegistry) @@ -255,6 +262,43 @@ } } + function populateOneKeyCommands() { + for (var key in keyToCommandRegistry) + { + if (getActualKeyStrokeLength(key) == 1) + oneKeyCommands.push(key); + } + } + + function generateCompletionKeys() { + var splitHash = splitKeyQueue(keyQueue); + command = splitHash.command; + count = splitHash.count; + + var completionKeys = oneKeyCommands.slice(0); + + if (getActualKeyStrokeLength(command) == 1) + { + for (var key in keyToCommandRegistry) + { + // NOTE(ilya): This won't work if we allow keys like <c-x><c-y>. + if (key[0] == command) + completionKeys.push(key.substring(1)); + } + } + + return completionKeys; + } + + function splitKeyQueue(queue) + { + var match = /([0-9]*)(.*)/.exec(queue); + var count = parseInt(match[1]); + var command = match[2]; + + return {count: count, command: command}; + } + function handleKeyDown(key) { console.log("checking keyQueue: [", keyQueue + key, "]"); keyQueue = checkKeyQueue(keyQueue + key); @@ -262,9 +306,9 @@ } function checkKeyQueue(keysToCheck) { - var match = /([0-9]*)(.*)/.exec(keysToCheck); - var count = parseInt(match[1]); - var command = match[2]; + var splitHash = splitKeyQueue(keysToCheck); + command = splitHash.command; + count = splitHash.count; if (command.length == 0) { return keysToCheck; } if (isNaN(count)) { count = 1; } @@ -296,9 +340,10 @@ function init() { populateValidFirstKeys(); + populateOneKeyCommands(); } init(); </script> </head> -</html>
\ No newline at end of file +</html> |
