aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/vimium_frontend.coffee
diff options
context:
space:
mode:
authorStephen Blott2016-02-28 14:01:16 +0000
committerStephen Blott2016-03-05 05:38:30 +0000
commit520b63cb1d64fb5a293988122007bd05bacc49db (patch)
treef3fd0d50edb493e24a543e6627bcd9c975e82c23 /content_scripts/vimium_frontend.coffee
parentcf7a03dc26415528bc690147ba72c08e67dd65c8 (diff)
downloadvimium-520b63cb1d64fb5a293988122007bd05bacc49db.tar.bz2
Key bindings; fix tests...
... and fix two bugs: - not suppressing keyup event after keyChar matched in keydown. - we cannot check the passKeys keyChar in keyup because the key state has changed; so we track what the next keyup response should be.
Diffstat (limited to 'content_scripts/vimium_frontend.coffee')
-rw-r--r--content_scripts/vimium_frontend.coffee67
1 files changed, 33 insertions, 34 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 2fc2dc35..e821b136 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -93,42 +93,41 @@ handlerStack.push
target = target.parentElement
true
-# Only exported for tests.
-window.initializeModes = ->
- class NormalMode extends KeyHandlerMode
- constructor: ->
- super
- name: "normal"
- indicator: false # There is no mode indicator in normal mode.
- commandHandler: @commandHandler.bind this
- keyMapping: {}
-
- chrome.storage.local.get "normalModeKeyStateMapping", (items) =>
- @setKeyMapping items.normalModeKeyStateMapping
-
- chrome.storage.onChanged.addListener (changes, area) =>
- if area == "local" and changes.normalModeKeyStateMapping?.newValue
- @setKeyMapping changes.normalModeKeyStateMapping.newValue
-
- commandHandler: (registryEntry, count) ->
- count *= registryEntry.options.count ? 1
- count = 1 if registryEntry.noRepeat
-
- if registryEntry.repeatLimit? and registryEntry.repeatLimit < count
- return unless confirm """
- You have asked Vimium to perform #{count} repeats of the command: #{registryEntry.description}.\n
- Are you sure you want to continue?"""
-
- if registryEntry.isBackgroundCommand
- chrome.runtime.sendMessage {handler: "runBackgroundCommand", frameId, registryEntry, count}
- else if registryEntry.passCountToFunction
- Utils.invokeCommandString registryEntry.command, [count]
- else
- Utils.invokeCommandString registryEntry.command for i in [0...count]
-
+class NormalMode extends KeyHandlerMode
+ constructor: (options = {}) ->
+ super extend options,
+ name: "normal"
+ indicator: false # There is no mode indicator in normal mode.
+ commandHandler: @commandHandler.bind this
+
+ chrome.storage.local.get "normalModeKeyStateMapping", (items) =>
+ @setKeyMapping items.normalModeKeyStateMapping
+
+ chrome.storage.onChanged.addListener (changes, area) =>
+ if area == "local" and changes.normalModeKeyStateMapping?.newValue
+ @setKeyMapping changes.normalModeKeyStateMapping.newValue
+
+ commandHandler: (registryEntry, count) ->
+ count *= registryEntry.options.count ? 1
+ count = 1 if registryEntry.noRepeat
+
+ if registryEntry.repeatLimit? and registryEntry.repeatLimit < count
+ return unless confirm """
+ You have asked Vimium to perform #{count} repeats of the command: #{registryEntry.description}.\n
+ Are you sure you want to continue?"""
+
+ if registryEntry.isBackgroundCommand
+ chrome.runtime.sendMessage {handler: "runBackgroundCommand", frameId, registryEntry, count}
+ else if registryEntry.passCountToFunction
+ Utils.invokeCommandString registryEntry.command, [count]
+ else
+ Utils.invokeCommandString registryEntry.command for i in [0...count]
+
+# Only exported for tests; also, "args..." is only for the tests.
+window.initializeModes = (args...) ->
# Install the permanent modes. The permanently-installed insert mode tracks focus/blur events, and
# activates/deactivates itself accordingly.
- normalMode = new NormalMode
+ normalMode = new NormalMode args...
new PassKeysMode normalMode
new InsertMode permanent: true
Scroller.init()