diff options
| author | ilya | 2009-12-30 14:55:24 -0800 |
|---|---|---|
| committer | ilya | 2009-12-30 15:36:32 -0800 |
| commit | 0140985511931e492ca8778a71bd462bc2f23776 (patch) | |
| tree | 2ab5061beb8b32832fda844034758e4f1ce067b7 /background_page.html | |
| parent | 5a36aaa7b7beb9a29c355fc77d95126ffdf19715 (diff) | |
| download | vimium-0140985511931e492ca8778a71bd462bc2f23776.tar.bz2 | |
Refresh the completion keys on every keystroke sent to the background page. This is the first pass at fixing issue #34.
Diffstat (limited to 'background_page.html')
| -rw-r--r-- | background_page.html | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/background_page.html b/background_page.html index 9640ab50..31705964 100644 --- a/background_page.html +++ b/background_page.html @@ -279,8 +279,12 @@ } } - function generateCompletionKeys() { - var splitHash = splitKeyQueue(keyQueue); + /* + * Generates a list of keys that can complete a valid command given the current key queue or the one passed + * in. + */ + function generateCompletionKeys(keysToCheck) { + var splitHash = splitKeyQueue(keysToCheck || keyQueue); command = splitHash.command; count = splitHash.count; @@ -308,13 +312,14 @@ return {count: count, command: command}; } - function handleKeyDown(key) { + function handleKeyDown(key, port) { console.log("checking keyQueue: [", keyQueue + key, "]"); - keyQueue = checkKeyQueue(keyQueue + key); + keyQueue = checkKeyQueue(keyQueue + key, port.tab.id); console.log("new KeyQueue: " + keyQueue); } - function checkKeyQueue(keysToCheck) { + function checkKeyQueue(keysToCheck, tabId) { + var refreshedCompletionKeys = false; var splitHash = splitKeyQueue(keysToCheck); command = splitHash.command; count = splitHash.count; @@ -329,22 +334,34 @@ if (typeof(registryEntry) == "string") { chrome.tabs.getSelected(null, function(tab) { var port = chrome.tabs.connect(tab.id, { name: "executePageCommand" }); - port.postMessage({ command: registryEntry, count: count }); + port.postMessage({ command: registryEntry, count: count, + completionKeys: generateCompletionKeys("") }); }); + refreshedCompletionKeys = true; } else { repeatFunction(registryEntry, count, 0); } - return ""; + newKeyQueue = ""; } else if (command.length > 1) { // The second key might be a valid command by its self. if (keyToCommandRegistry[command[1]]) - return checkKeyQueue(command[1]); + newKeyQueue = checkKeyQueue(command[1]); else - return (validFirstKeys[command[1]] ? command[1] : ""); + newKeyQueue = (validFirstKeys[command[1]] ? command[1] : ""); } else { - return (validFirstKeys[command] ? count.toString() + command : ""); + newKeyQueue = (validFirstKeys[command] ? count.toString() + command : ""); + } + + // If we haven't sent the completion keys piggybacked on executePageCommand, + // send them by themselves. + if (!refreshedCompletionKeys) + { + var port = chrome.tabs.connect(tabId, { name: "refreshCompletionKeys" }); + port.postMessage({ completionKeys: generateCompletionKeys(newKeyQueue) }); } + + return newKeyQueue; } function init() { |
