From 77a2c6b41959f978147bd953ac94f5484394b276 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 29 Mar 2016 15:51:24 +0100 Subject: Fix race condition in grab-back-focus. See the newly-added comment. --- content_scripts/vimium_frontend.coffee | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 93ab440a..b9249e73 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -49,14 +49,17 @@ class GrabBackFocus extends Mode mousedown: => @alwaysContinueBubbling => @exit() Settings.use "grabBackFocus", (grabBackFocus) => - if 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 - else - @exit() + # It is possible that this mode exits (e.g. due to a key event) before the settings are ready -- in + # which case we should not install this grab-back-focus watcher. + if @modeIsActive + if 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 + else + @exit() grabBackFocus: (element) -> return @continueBubbling unless DomUtils.isEditable element -- cgit v1.2.3