aboutsummaryrefslogtreecommitdiffstats
path: root/vimiumFrontend.js
diff options
context:
space:
mode:
Diffstat (limited to 'vimiumFrontend.js')
-rw-r--r--vimiumFrontend.js54
1 files changed, 33 insertions, 21 deletions
diff --git a/vimiumFrontend.js b/vimiumFrontend.js
index 2428e4aa..eb0216f4 100644
--- a/vimiumFrontend.js
+++ b/vimiumFrontend.js
@@ -20,6 +20,7 @@ var saveZoomLevelPort;
var isEnabledForUrl = true;
// The user's operating system.
var currentCompletionKeys;
+var validFirstKeys;
var linkHintCss;
// TODO(philc): This should be pulled from the extension's storage when the page loads.
@@ -71,6 +72,7 @@ var settings = {
frameId = Math.floor(Math.random()*999999999)
var hasModifiersRegex = /^<([amc]-)+.>/;
+var googleRegex = /:\/\/[^/]*google[^/]+/;
/*
* Complete initialization work that sould be done prior to DOMReady, like setting the page's zoom level.
@@ -94,20 +96,21 @@ function initializePreDomReady() {
keyPort = chrome.extension.connect({ name: "keyDown" });
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
- if (request.name == "hideUpgradeNotification")
+ if (request.name == "hideUpgradeNotification") {
HUD.hideUpgradeNotification();
- else if (request.name == "showUpgradeNotification" && isEnabledForUrl)
+ } else if (request.name == "showUpgradeNotification" && isEnabledForUrl) {
HUD.showUpgradeNotification(request.version);
- else if (request.name == "showHelpDialog")
+ } else if (request.name == "showHelpDialog") {
if (isShowingHelpDialog)
hideHelpDialog();
else
showHelpDialog(request.dialogHtml, request.frameId);
- else if (request.name == "focusFrame")
- if(frameId == request.frameId)
+ } else if (request.name == "focusFrame") {
+ if (frameId == request.frameId)
focusThisFrame(request.highlight);
- else if (request.name == "refreshCompletionKeys")
- refreshCompletionKeys(request.completionKeys);
+ } else if (request.name == "refreshCompletionKeys") {
+ refreshCompletionKeys(request);
+ }
sendResponse({}); // Free up the resources used by this open connection.
});
@@ -122,7 +125,7 @@ function initializePreDomReady() {
}
}
- refreshCompletionKeys(args.completionKeys);
+ refreshCompletionKeys(args);
});
}
else if (port.name == "getScrollPosition") {
@@ -203,12 +206,12 @@ function initializeOnDomReady() {
};
// This is a little hacky but sometimes the size wasn't available on domReady?
-function registerFrameIfSizeAvailable (top) {
+function registerFrameIfSizeAvailable (is_top) {
if (innerWidth != undefined && innerWidth != 0 && innerHeight != undefined && innerHeight != 0)
chrome.extension.sendRequest({ handler: "registerFrame", frameId: frameId,
- area: innerWidth * innerHeight, top: top, total: frames.length + 1 });
+ area: innerWidth * innerHeight, is_top: is_top, total: frames.length + 1 });
else
- setTimeout(function () { registerFrameIfSizeAvailable(top); }, 100);
+ setTimeout(function () { registerFrameIfSizeAvailable(is_top); }, 100);
}
/*
@@ -431,8 +434,8 @@ function onKeydown(event) {
exitInsertMode();
// Added to prevent Google Instant from reclaiming the keystroke and putting us back into the search box.
- // TOOD(ilya): Revisit this. Not sure it's the absolute best approach.
- event.stopPropagation();
+ if (isGoogleSearch())
+ event.stopPropagation();
}
}
else if (findMode)
@@ -473,7 +476,8 @@ function onKeydown(event) {
// Subject to internationalization issues since we're using keyIdentifier instead of charCode (in keypress).
//
// TOOD(ilya): Revisit this. Not sure it's the absolute best approach.
- if (keyChar == "" && !insertMode && currentCompletionKeys.indexOf(getKeyChar(event)) != -1)
+ if (keyChar == "" && !insertMode
+ && (currentCompletionKeys.indexOf(getKeyChar(event)) != -1 || validFirstKeys[getKeyChar(event)]))
event.stopPropagation();
}
@@ -495,13 +499,21 @@ function checkIfEnabledForUrl() {
});
}
-function refreshCompletionKeys(completionKeys) {
- if (completionKeys)
- currentCompletionKeys = completionKeys;
- else
- chrome.extension.sendRequest({handler: "getCompletionKeys"}, function (response) {
- currentCompletionKeys = response.completionKeys;
- });
+// TODO(ilya): This just checks if "google" is in the domain name. Probably should be more targeted.
+function isGoogleSearch() {
+ var url = window.location.toString();
+ return !!url.match(googleRegex);
+}
+
+function refreshCompletionKeys(response) {
+ if (response) {
+ currentCompletionKeys = response.completionKeys;
+
+ if (response.validFirstKeys)
+ validFirstKeys = response.validFirstKeys;
+ } else {
+ chrome.extension.sendRequest({ handler: "getCompletionKeys" }, refreshCompletionKeys);
+ }
}
function onFocusCapturePhase(event) {