aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-01-02 08:11:22 +0000
committerStephen Blott2015-01-02 08:16:20 +0000
commita321ca5e1a335f0b04714fa8ea00c2bac8febb86 (patch)
tree2b25cc69ca41d0a3454b4065ddf38c8fa49c2fa6
parentc783b653e185166009ba0cdf94c6fdbb442d7f39 (diff)
downloadvimium-a321ca5e1a335f0b04714fa8ea00c2bac8febb86.tar.bz2
Modes; flesh out passkeys mode.
-rw-r--r--content_scripts/mode_passkeys.coffee32
-rw-r--r--content_scripts/vimium_frontend.coffee20
-rw-r--r--manifest.json1
3 files changed, 42 insertions, 11 deletions
diff --git a/content_scripts/mode_passkeys.coffee b/content_scripts/mode_passkeys.coffee
new file mode 100644
index 00000000..7a0249ad
--- /dev/null
+++ b/content_scripts/mode_passkeys.coffee
@@ -0,0 +1,32 @@
+
+class PassKeysMode extends Mode
+ keyQueue: ""
+ passKeys: ""
+
+ # Decide whether this keyChar should be passed to the underlying page. Keystrokes are *never* considered
+ # passKeys if the keyQueue is not empty. So, for example, if 't' is a passKey, then 'gt' and '99t' will
+ # neverthless be handled by vimium.
+ isPassKey: (keyChar) ->
+ not @keyQueue and 0 <= @passKeys.indexOf(keyChar)
+
+ handlePassKeyEvent: (event) ->
+ for keyChar in [KeyboardUtils.getKeyChar(event), String.fromCharCode(event.charCode)]
+ # A key is passed through to the underlying page by returning handlerStack.passThrough.
+ return handlerStack.passThrough if keyChar and @isPassKey keyChar
+ true
+
+ setState: (response) ->
+ if response.isEnabledForUrl?
+ @passKeys = (response.isEnabledForUrl and response.passKeys) or ""
+ if response.keyQueue?
+ @keyQueue = response.keyQueue
+
+ constructor: ->
+ super
+ name: "passkeys"
+ keydown: (event) => @handlePassKeyEvent event
+ keypress: (event) => @handlePassKeyEvent event
+ keyup: -> true # Allow event to propagate.
+
+root = exports ? window
+root.PassKeysMode = PassKeysMode
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index b40e9735..409cf96b 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -6,6 +6,7 @@
#
insertMode = null
+passKeysMode = null
insertModeLock = null
findMode = false
findModeQuery = { rawQuery: "", matchCount: 0 }
@@ -110,7 +111,7 @@ initializePreDomReady = ->
settings.addEventListener("load", LinkHints.init.bind(LinkHints))
settings.load()
- # Install normal mode. This will be at the bottom of both the mode stack and the handler stack, and is never
+ # Install normal mode. This is at the bottom of both the mode stack and the handler stack, and is never
# deactivated.
new Mode
name: "normal"
@@ -118,7 +119,7 @@ initializePreDomReady = ->
keypress: onKeypress
keyup: onKeyup
- # Initialize the scroller. The scroller installs key handlers, and these will be next on the handler stack,
+ # Initialize the scroller. The scroller install a key handler, and this is next on the handler stack,
# immediately above normal mode.
Scroller.init settings
@@ -127,14 +128,8 @@ initializePreDomReady = ->
return handlerStack.passThrough if keyChar and isPassKey keyChar
true
- # Install passKeys mode. This mode is never deactivated.
- new Mode
- name: "passkeys"
- keydown: handlePassKeyEvent
- keypress: handlePassKeyEvent
- keyup: -> true # Allow event to propagate.
-
- # Install insert mode.
+ # Install passKeys and insert modes. These too are permanently on the stack (although not always active).
+ passKeysMode = new PassKeysMode()
insertMode = new InsertMode()
checkIfEnabledForUrl()
@@ -163,7 +158,7 @@ initializePreDomReady = ->
executePageCommand: executePageCommand
getActiveState: -> { enabled: isEnabledForUrl, passKeys: passKeys, badge: Mode.getBadge() }
setState: setState
- currentKeyQueue: (request) -> keyQueue = request.keyQueue
+ currentKeyQueue: (request) -> passKeysMode.setState request
chrome.runtime.onMessage.addListener (request, sender, sendResponse) ->
# In the options page, we will receive requests from both content and background scripts. ignore those
@@ -208,6 +203,7 @@ setState = (request) ->
initializeWhenEnabled(request.passKeys) if request.enabled
isEnabledForUrl = request.enabled
passKeys = request.passKeys
+ passKeysMode.setState request
#
# The backend needs to know which frame has focus.
@@ -395,6 +391,7 @@ extend window,
# Keystrokes are *never* considered passKeys if the keyQueue is not empty. So, for example, if 't' is a
# passKey, then 'gt' and '99t' will neverthless be handled by vimium.
isPassKey = ( keyChar ) ->
+ return false # Diabled.
return !keyQueue and passKeys and 0 <= passKeys.indexOf(keyChar)
# Track which keydown events we have handled, so that we can subsequently suppress the corresponding keyup
@@ -557,6 +554,7 @@ checkIfEnabledForUrl = ->
url = window.location.toString()
chrome.runtime.sendMessage { handler: "isEnabledForUrl", url: url }, (response) ->
+ passKeysMode.setState response
isEnabledForUrl = response.isEnabledForUrl
if (isEnabledForUrl)
initializeWhenEnabled(response.passKeys)
diff --git a/manifest.json b/manifest.json
index 5f810d54..c47a4a88 100644
--- a/manifest.json
+++ b/manifest.json
@@ -45,6 +45,7 @@
"content_scripts/marks.js",
"content_scripts/mode.js",
"content_scripts/mode_insert.js",
+ "content_scripts/mode_passkeys.js",
"content_scripts/vimium_frontend.js"
],
"css": ["content_scripts/vimium.css"],