From 8975229fd637ca1a91d7c52beb5969fe2b5e4d27 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 28 Apr 2015 13:31:01 +0100 Subject: Activate grab-back-focus only if enabled. This turned out to be trickier than expected. It turns out there's a period after document.body is defined but before the DOM is ready when we can't use the HUD (but previously thought we could, ie. HUD.isReady returned true). --- content_scripts/mode.coffee | 3 ++- content_scripts/vimium_frontend.coffee | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index a2ac5b8c..f631b4cd 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -57,7 +57,8 @@ class Mode # undefined, then the request propagates to the next mode. # The active indicator can also be changed with @setIndicator(). if @options.indicator? - if @options.indicator then HUD?.show @options.indicator else HUD?.hide true, false + if HUD?.isReady() + if @options.indicator then HUD.show @options.indicator else HUD.hide true, false @stopBubblingAndTrue else @continueBubbling diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index bc1f7687..c9410f90 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -13,6 +13,7 @@ isShowingHelpDialog = false keyPort = null isEnabledForUrl = true isIncognitoMode = chrome.extension.inIncognitoContext +isDomReady = false passKeys = null keyQueue = null # The user's operating system. @@ -149,7 +150,6 @@ window.initializeModes = -> new NormalMode new PassKeysMode new InsertMode permanent: true - new GrabBackFocus Scroller.init settings # @@ -229,7 +229,9 @@ window.installListeners = -> do (type) -> installListener window, type, (event) -> handlerStack.bubbleEvent type, event installListener document, "DOMActivate", (event) -> handlerStack.bubbleEvent 'DOMActivate', event installedListeners = true + # Other once-only initialisation. FindModeHistory.init() + new GrabBackFocus if isEnabledForUrl # # Whenever we get the focus: @@ -252,6 +254,7 @@ window.addEventListener "hashchange", onFocus # Initialization tasks that must wait for the document to be ready. # initializeOnDomReady = -> + isDomReady = true # Tell the background page we're in the dom ready state. chrome.runtime.connect({ name: "domReady" }) CursorHider.init() @@ -1153,7 +1156,7 @@ HUD = else HUD._tweenId = Tween.fade HUD.displayElement(), 0, 150, -> HUD.hide true, updateIndicator - isReady: -> document.body != null + isReady: -> document.body != null and isDomReady # A preference which can be toggled in the Options page. */ enabled: -> !settings.get("hideHud") -- cgit v1.2.3