diff options
| author | mrmr1993 | 2017-10-24 18:36:23 +0100 |
|---|---|---|
| committer | mrmr1993 | 2017-10-27 18:20:23 +0100 |
| commit | 51fa63a5e97167b015acf7b80d673d081c2b91da (patch) | |
| tree | c6a8a7ddd9a9923c03404921954688070b440fa6 /content_scripts | |
| parent | fe6fbca08e501e2478bf10da402d5b4f42a89ade (diff) | |
| download | vimium-51fa63a5e97167b015acf7b80d673d081c2b91da.tar.bz2 | |
Move NormalMode to its own content script
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/mode_normal.coffee | 38 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 35 |
2 files changed, 38 insertions, 35 deletions
diff --git a/content_scripts/mode_normal.coffee b/content_scripts/mode_normal.coffee new file mode 100644 index 00000000..3e1b1ee3 --- /dev/null +++ b/content_scripts/mode_normal.coffee @@ -0,0 +1,38 @@ +class NormalMode extends KeyHandlerMode + constructor: (options = {}) -> + defaults = + name: "normal" + indicator: false # There is normally no mode indicator in normal mode. + commandHandler: @commandHandler.bind this + + super extend defaults, options + + 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: ({command: 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} repetitions of the command: #{registryEntry.description}.\n + Are you sure you want to continue?""" + + if registryEntry.topFrame + # We never return to a UI-component frame (e.g. the help dialog), it might have lost the focus. + sourceFrameId = if window.isVimiumUIComponent then 0 else frameId + chrome.runtime.sendMessage + handler: "sendMessageToFrames", message: {name: "runInTopFrame", sourceFrameId, registryEntry} + else if registryEntry.background + chrome.runtime.sendMessage {handler: "runBackgroundCommand", registryEntry, count} + else + Utils.invokeCommandString registryEntry.command, count, {registryEntry} + +root = exports ? (window.root ?= {}) +root.NormalMode = NormalMode +extend window, root unless exports? diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 86e3b682..add7b7f4 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -117,41 +117,6 @@ handlerStack.push target = target.parentElement true -class NormalMode extends KeyHandlerMode - constructor: (options = {}) -> - defaults = - name: "normal" - indicator: false # There is normally no mode indicator in normal mode. - commandHandler: @commandHandler.bind this - - super extend defaults, options - - 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: ({command: 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} repetitions of the command: #{registryEntry.description}.\n - Are you sure you want to continue?""" - - if registryEntry.topFrame - # We never return to a UI-component frame (e.g. the help dialog), it might have lost the focus. - sourceFrameId = if window.isVimiumUIComponent then 0 else frameId - chrome.runtime.sendMessage - handler: "sendMessageToFrames", message: {name: "runInTopFrame", sourceFrameId, registryEntry} - else if registryEntry.background - chrome.runtime.sendMessage {handler: "runBackgroundCommand", registryEntry, count} - else - Utils.invokeCommandString registryEntry.command, count, {registryEntry} - installModes = -> # Install the permanent modes. The permanently-installed insert mode tracks focus/blur events, and # activates/deactivates itself accordingly. |
