aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-02-14 12:19:22 +0000
committerStephen Blott2015-02-14 12:19:22 +0000
commit05f229201a05101ab4947bd436ec02d8864392f9 (patch)
treeb4dd76e7980534e7c0a9b9b62f62c1fffb16646b
parent358f1ebfddacf75c02bb3a2e8993bab6d2fe28d8 (diff)
downloadvimium-05f229201a05101ab4947bd436ec02d8864392f9.tar.bz2
Grab back focus: use settings.addEventListener "load".
Doh! I didn't know this existed.
-rw-r--r--background_scripts/settings.coffee5
-rw-r--r--content_scripts/vimium_frontend.coffee12
2 files changed, 6 insertions, 11 deletions
diff --git a/background_scripts/settings.coffee b/background_scripts/settings.coffee
index a60f2e09..3528e8a9 100644
--- a/background_scripts/settings.coffee
+++ b/background_scripts/settings.coffee
@@ -113,13 +113,10 @@ root.Settings = Settings =
# put in an example search engine
searchEngines: "w: http://www.wikipedia.org/w/index.php?title=Special:Search&search=%s wikipedia"
newTabUrl: "chrome://newtab"
+ grabBackFocus: false
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 51b0695f..741b54af 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -44,7 +44,7 @@ settings =
loadedValues: 0
valuesToLoad: [ "scrollStepSize", "linkHintCharacters", "linkHintNumbers", "filterLinkHints", "hideHud",
"previousPatterns", "nextPatterns", "regexFindMode", "userDefinedLinkHintCss",
- "helpDialog_showAdvancedCommands", "smoothScroll" ]
+ "helpDialog_showAdvancedCommands", "smoothScroll", "grabBackFocus" ]
isLoaded: false
eventListeners: {}
@@ -108,18 +108,16 @@ class GrabBackFocus extends Mode
_name: "grab-back-focus-mousedown"
mousedown: => @alwaysContinueBubbling => @exit()
- # 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
+ activate = =>
+ return @exit() unless settings.get "grabBackFocus"
@push
_name: "grab-back-focus-focus"
focus: (event) => @grabBackFocus event.target
# An input may already be focused. If so, grab back the focus.
@grabBackFocus document.activeElement if document.activeElement
+ if settings.isLoaded then activate() else settings.addEventListener "load", activate
+
grabBackFocus: (element) ->
return @continueBubbling unless DomUtils.isEditable element
element.blur()