From 51fa63a5e97167b015acf7b80d673d081c2b91da Mon Sep 17 00:00:00 2001
From: mrmr1993
Date: Tue, 24 Oct 2017 18:36:23 +0100
Subject: Move NormalMode to its own content script
---
content_scripts/mode_normal.coffee | 38 ++++++++++++++++++++++++++++++++++
content_scripts/vimium_frontend.coffee | 35 -------------------------------
manifest.json | 1 +
pages/blank.html | 1 +
pages/completion_engines.html | 1 +
pages/help_dialog.html | 1 +
pages/logging.html | 1 +
pages/options.html | 1 +
tests/dom_tests/dom_tests.html | 1 +
9 files changed, 45 insertions(+), 35 deletions(-)
create mode 100644 content_scripts/mode_normal.coffee
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.
diff --git a/manifest.json b/manifest.json
index f90278b7..71d7caba 100644
--- a/manifest.json
+++ b/manifest.json
@@ -60,6 +60,7 @@
"content_scripts/mode_key_handler.js",
"content_scripts/mode_visual.js",
"content_scripts/hud.js",
+ "content_scripts/mode_normal.js",
"content_scripts/vimium_frontend.js"
],
"css": ["content_scripts/vimium.css"],
diff --git a/pages/blank.html b/pages/blank.html
index 8f10c7f6..d026912e 100644
--- a/pages/blank.html
+++ b/pages/blank.html
@@ -19,6 +19,7 @@
+
diff --git a/pages/completion_engines.html b/pages/completion_engines.html
index 0c86edf7..3313b26c 100644
--- a/pages/completion_engines.html
+++ b/pages/completion_engines.html
@@ -22,6 +22,7 @@
+
diff --git a/pages/help_dialog.html b/pages/help_dialog.html
index 1da54efd..7f053265 100644
--- a/pages/help_dialog.html
+++ b/pages/help_dialog.html
@@ -19,6 +19,7 @@
+
diff --git a/pages/logging.html b/pages/logging.html
index 6eff58c4..17aafd70 100644
--- a/pages/logging.html
+++ b/pages/logging.html
@@ -19,6 +19,7 @@
+
diff --git a/pages/options.html b/pages/options.html
index 46307b6f..6312e450 100644
--- a/pages/options.html
+++ b/pages/options.html
@@ -20,6 +20,7 @@
+
diff --git a/tests/dom_tests/dom_tests.html b/tests/dom_tests/dom_tests.html
index d2e795d1..37cd43e3 100644
--- a/tests/dom_tests/dom_tests.html
+++ b/tests/dom_tests/dom_tests.html
@@ -49,6 +49,7 @@
+
--
cgit v1.2.3