aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2014-08-23 15:26:03 +0100
committerStephen Blott2014-08-23 15:26:03 +0100
commit951f8839d02a8d85747d86ccd09efc0ee3a72501 (patch)
tree9d1da52d3e24b2215d3c4fb32302460774ceedfd
parent3581b585acf996fb8515c11d30682269557301c2 (diff)
downloadvimium-951f8839d02a8d85747d86ccd09efc0ee3a72501.tar.bz2
Allow passing of keys to the underlying page (more minor code review).
-rw-r--r--background_scripts/main.coffee34
-rw-r--r--content_scripts/vimium_frontend.coffee3
2 files changed, 19 insertions, 18 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)
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 70cc5cbb..feebda07 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -117,6 +117,7 @@ initializePreDomReady = ->
getScrollPosition: -> scrollX: window.scrollX, scrollY: window.scrollY
setScrollPosition: (request) -> setScrollPosition request.scrollX, request.scrollY
executePageCommand: executePageCommand
+ # FIXME: currentKeyQueue(), below, does not respect the frameId. Should it?
currentKeyQueue: (request) -> keyQueue = request.keyQueue
getActiveState: -> { enabled: isEnabledForUrl }
disableVimium: disableVimium
@@ -329,7 +330,7 @@ extend window,
# passKey, then 'gt' and '99t' will neverthless be handled by vimium.
# TODO: This currently only works for unmodified keys (so not for '<c-a>', or the like). It's not clear if
# this is a problem or not. I don't recall coming across a web page with modifier key bindings. Such
-# bindings might be too likely to conflict with browser bindings.
+# bindings might be too likely to conflict with browsers' native bindings.
isPassKey = ( keyChar ) ->
!keyQueue and passKeys and 0 <= passKeys.indexOf keyChar