aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--background_scripts/settings.coffee5
-rw-r--r--content_scripts/vimium_frontend.coffee11
-rw-r--r--pages/options.coffee2
-rw-r--r--pages/options.html6
4 files changed, 16 insertions, 8 deletions
diff --git a/background_scripts/settings.coffee b/background_scripts/settings.coffee
index 4342aa26..a60f2e09 100644
--- a/background_scripts/settings.coffee
+++ b/background_scripts/settings.coffee
@@ -73,7 +73,6 @@ root.Settings = Settings =
linkHintNumbers: "0123456789"
filterLinkHints: false
hideHud: false
- grabBackfocus: false
userDefinedLinkHintCss:
"""
div > .vimiumHintMarker {
@@ -117,6 +116,10 @@ root.Settings = Settings =
settingsVersion: Utils.getCurrentVersion()
+ # NOTE. This setting is accessed directly via chrome.storage.sync in the front end. There, we assume that
+ # the default value is false.
+ grabBackFocus: false
+
# We use settingsVersion to coordinate any necessary schema changes.
if Utils.compareVersions("1.42", Settings.get("settingsVersion")) != -1
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 3cbf2d53..51b0695f 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -96,7 +96,8 @@ settings =
#
frameId = Math.floor(Math.random()*999999999)
-# If an input grabs the focus before the user has interacted with the page, then grab it back.
+# If an input grabs the focus before the user has interacted with the page, then grab it back (if the
+# grabBackFocus option is set).
class GrabBackFocus extends Mode
constructor: ->
super
@@ -107,8 +108,12 @@ class GrabBackFocus extends Mode
_name: "grab-back-focus-mousedown"
mousedown: => @alwaysContinueBubbling => @exit()
- chrome.storage.sync.get "grabBackfocus", (items) =>
- return @exit() unless items.grabBackfocus and not chrome.runtime.lastError
+ # HACK. We use chrome.storage.sync directly here (rather than settings). This avoids a race condition.
+ # An input can be focused by the page either before we install our handlers or after, and we handle both
+ # cases. There's no uncertainty period while we wait to learn whether the option is set or not.
+ # Note. We also assume that the default value for grabBackFocus is false.
+ chrome.storage.sync.get "grabBackFocus", (items) =>
+ return @exit() if chrome.runtime.lastError or not items.grabBackFocus
@push
_name: "grab-back-focus-focus"
focus: (event) => @grabBackFocus event.target
diff --git a/pages/options.coffee b/pages/options.coffee
index 525508fd..d2950348 100644
--- a/pages/options.coffee
+++ b/pages/options.coffee
@@ -257,7 +257,7 @@ initOptionsPage = ->
regexFindMode: CheckBoxOption
scrollStepSize: NumberOption
smoothScroll: CheckBoxOption
- grabBackfocus: CheckBoxOption
+ grabBackFocus: CheckBoxOption
searchEngines: TextOption
searchUrl: NonEmptyTextOption
userDefinedLinkHintCss: TextOption
diff --git a/pages/options.html b/pages/options.html
index 6df2c92b..889d5ea0 100644
--- a/pages/options.html
+++ b/pages/options.html
@@ -133,12 +133,12 @@ b: http://b.com/?q=%s description
<td verticalAlign="top" class="booleanOption">
<div class="help">
<div class="example">
- Prevent the page from focusing an input on load
+ Prevent pages from focusing an input on load (e.g. Google, Bing, etc.).
</div>
</div>
<label>
- <input id="grabBackfocus" type="checkbox"/>
- Grab back focus
+ <input id="grabBackFocus" type="checkbox"/>
+ Don't let pages steal the focus on load
</label>
</td>
</tr>