diff options
| author | Stephen Blott | 2014-08-23 15:26:03 +0100 |
|---|---|---|
| committer | Stephen Blott | 2014-08-23 15:26:03 +0100 |
| commit | 951f8839d02a8d85747d86ccd09efc0ee3a72501 (patch) | |
| tree | 9d1da52d3e24b2215d3c4fb32302460774ceedfd /background_scripts | |
| parent | 3581b585acf996fb8515c11d30682269557301c2 (diff) | |
| download | vimium-951f8839d02a8d85747d86ccd09efc0ee3a72501.tar.bz2 | |
Allow passing of keys to the underlying page (more minor code review).
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/main.coffee | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 6d986187..46a6a695 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -76,20 +76,18 @@ isEnabledForUrl = (request) -> # Excluded URLs are stored as a series of URL expressions and optional passKeys, separated by newlines. # Lines for which the first non-blank character is "#" are comments. excludedLines = (line.trim() for line in Settings.get("excludedUrls").split("\n")) - excludedUrls = (line for line in excludedLines when line and line.indexOf("#") != 0) - for spec in excludedUrls - parse = spec.split(/\s+/) - if parse.length - url = parse[0] - # The user can add "*" to the URL which means ".*" - regexp = new RegExp("^" + url.replace(/\*/g, ".*") + "$") - if request.url.match(regexp) - passKeys = parse[1..].join("") - if passKeys - # Enabled, but only for these keys. - return { isEnabledForUrl: true, passKeys: passKeys } - # Disabled. - return { isEnabledForUrl: false } + excludedSpecs = (line.split(/\s+/) for line in excludedLines when line and line.indexOf("#") != 0) + for spec in excludedSpecs + url = spec[0] + # The user can add "*" to the URL which means ".*" + regexp = new RegExp("^" + url.replace(/\*/g, ".*") + "$") + if request.url.match(regexp) + passKeys = spec[1..].join("") + if passKeys + # Enabled, but not for these keys. + return { isEnabledForUrl: true, passKeys: passKeys } + # Wholly disabled. + return { isEnabledForUrl: false } # Enabled (the default). { isEnabledForUrl: true } @@ -513,9 +511,11 @@ handleKeyDown = (request, port) -> keyQueue = checkKeyQueue(keyQueue + key, port.sender.tab.id, request.frameId) console.log("new KeyQueue: " + keyQueue) # Tell the content script whether there are keys in the queue. If there are, then subsequent keys in passKeys will be - # handled by vimium. - # FIXME: There is a race condition here. The behaviour depends upon whether this message gets back - # to the content script before the next keystroke or not. + # handled by vimium. So, if 't' is a passKey, then 'gt' and '99t' will nevertheless be handled by Vimium. + # FIXME: There is a race condition here. The behaviour in the content script depends upon whether this message gets + # back there before or after the next keystroke. + # That being said, I suspect there are other similar race conditions here, for example in checkKeyQueue(). + # Steve (23 Aug, 14). chrome.tabs.sendMessage(port.sender.tab.id, name: "currentKeyQueue", keyQueue: keyQueue) |
