aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts
diff options
context:
space:
mode:
authorStephen Blott2015-02-12 10:52:56 +0000
committerStephen Blott2015-02-12 11:50:34 +0000
commitffc49d3057daee2354fb77d939fffc0cf77ff2e1 (patch)
tree892b319ce3622f6dba517d21db619e6312e9f017 /content_scripts
parent0ea060ca5b45acf42eb892cf900b8b7e04fc3397 (diff)
downloadvimium-ffc49d3057daee2354fb77d939fffc0cf77ff2e1.tar.bz2
Grab back focus...
- add new option "GrabBackFocus" - use chrome.storage.sync.get() to get option value - avoid race conditions on load - fix tests
Diffstat (limited to 'content_scripts')
-rw-r--r--content_scripts/vimium_frontend.coffee33
1 files changed, 16 insertions, 17 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index ddc19d3a..3cbf2d53 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -98,28 +98,27 @@ frameId = Math.floor(Math.random()*999999999)
# If an input grabs the focus before the user has interacted with the page, then grab it back.
class GrabBackFocus extends Mode
- constructor: (@insertMode) ->
- return if @shouldBeDeactivated()
- super name: "grab-focus", keydown: => @alwaysContinueBubbling => @exit()
+ constructor: ->
+ super
+ name: "grab-back-focus"
+ keydown: => @alwaysContinueBubbling => @exit()
@push
- _name: "grab-focus-handlers"
+ _name: "grab-back-focus-mousedown"
mousedown: => @alwaysContinueBubbling => @exit()
- focus: (event) => @grabBackFocus event.target
- # An input may already be focused. If so, grab back the focus.
- @grabBackFocus document.activeElement if document.activeElement
+ chrome.storage.sync.get "grabBackfocus", (items) =>
+ return @exit() unless items.grabBackfocus and not chrome.runtime.lastError
+ @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
grabBackFocus: (element) ->
- if DomUtils.isEditable(element) and not @shouldBeDeactivated()
- element.blur()
- @insertMode.exit null, element
- return @suppressEvent
- @exit() if @shouldBeDeactivated()
- @continueBubbling
-
- shouldBeDeactivated: ->
- false and settings.isLoaded and not settings.get "grabBackFocus"
+ return @continueBubbling unless DomUtils.isEditable element
+ element.blur()
+ @suppressEvent
# Only exported for tests.
window.initializeModes = ->
@@ -139,7 +138,7 @@ window.initializeModes = ->
new NormalMode
new PassKeysMode
new InsertMode permanent: true
- new GrabBackFocus InsertMode.permanentInstance
+ new GrabBackFocus
#
# Complete initialization work that sould be done prior to DOMReady.