aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorilya2009-12-30 14:55:24 -0800
committerilya2009-12-30 15:36:32 -0800
commit0140985511931e492ca8778a71bd462bc2f23776 (patch)
tree2ab5061beb8b32832fda844034758e4f1ce067b7
parent5a36aaa7b7beb9a29c355fc77d95126ffdf19715 (diff)
downloadvimium-0140985511931e492ca8778a71bd462bc2f23776.tar.bz2
Refresh the completion keys on every keystroke sent to the background page. This is the first pass at fixing issue #34.
-rw-r--r--background_page.html37
-rw-r--r--vimiumFrontend.js19
2 files changed, 43 insertions, 13 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() {
diff --git a/vimiumFrontend.js b/vimiumFrontend.js
index 4b4ee07e..e3c0c7de 100644
--- a/vimiumFrontend.js
+++ b/vimiumFrontend.js
@@ -44,9 +44,7 @@ function initializePreDomReady() {
var getZoomLevelPort = chrome.extension.connect({ name: "getZoomLevel" });
getZoomLevelPort.postMessage({ domain: window.location.host });
- chrome.extension.sendRequest({handler: "getCompletionKeys"}, function (response) {
- currentCompletionKeys = response.completionKeys;
- });
+ refreshCompletionKeys();
// Send the key to the key handler in the background page.
keyPort = chrome.extension.connect({ name: "keyDown" });
@@ -64,6 +62,8 @@ function initializePreDomReady() {
if (this[args.command]) {
for (var i = 0; i < args.count; i++) { this[args.command].call(); }
}
+
+ refreshCompletionKeys(args.completionKeys);
});
}
else if (port.name == "getScrollPosition") {
@@ -100,6 +100,10 @@ function initializePreDomReady() {
});
} else if (port.name == "returnSetting") {
port.onMessage.addListener(setSetting);
+ } else if (port.name == "refreshCompletionKeys") {
+ port.onMessage.addListener(function (args) {
+ refreshCompletionKeys(args.completionKeys);
+ });
}
});
}
@@ -261,6 +265,15 @@ function onKeydown(event) {
}
}
+function refreshCompletionKeys(completionKeys) {
+ if (completionKeys)
+ currentCompletionKeys = completionKeys;
+ else
+ chrome.extension.sendRequest({handler: "getCompletionKeys"}, function (response) {
+ currentCompletionKeys = response.completionKeys;
+ });
+}
+
function onFocusCapturePhase(event) {
if (isFocusable(event.target))
enterInsertMode();