From 19b33fed06ecf7d6dc6260e3f623a4190c059285 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Thu, 30 Apr 2015 21:58:04 +0100 Subject: Make GrabBackFocus work for javascript page transitions from links --- content_scripts/vimium_frontend.coffee | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'content_scripts/vimium_frontend.coffee') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 02e6c9ee..c1a205f2 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -133,6 +133,28 @@ class GrabBackFocus extends Mode element.blur() @suppressEvent +# Pages can load new content dynamically and change the displayed URL using history.pushState. Since this can +# often be indistinguishable from an actual new page load for the user, we should also re-start GrabBackFocus +# for these as well. +handlerStack.push + click: (event) -> + target = event.target + while target + # Often, a link which triggers a content load and url change with javascript will also have the new + # url as it's href attribute. + if target.tagName == "A" and + target.origin == document.location.origin and + # Clicking the link will change the url of this frame. + (target.pathName != document.location.pathName or + target.search != document.location.search) and + (target.target in ["", "_self"] or + (target.target == "_parent" and window.parent == window) or + (target.target == "_top" and window.top == window)) + return new GrabBackFocus() + else + target = target.parentElement + true + # Only exported for tests. window.initializeModes = -> class NormalMode extends Mode -- cgit v1.2.3 From 2bd819e98d85fbc5d463735afec53f3b5433fd2f Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Fri, 1 May 2015 06:32:02 +0100 Subject: Add extra information to GrabBackFocus' pushState helper --- content_scripts/vimium_frontend.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'content_scripts/vimium_frontend.coffee') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index c1a205f2..661ea1c4 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -135,8 +135,9 @@ class GrabBackFocus extends Mode # Pages can load new content dynamically and change the displayed URL using history.pushState. Since this can # often be indistinguishable from an actual new page load for the user, we should also re-start GrabBackFocus -# for these as well. +# for these as well. This fixes issue #1622. handlerStack.push + _name: "GrabBackFocus-pushState-monitor" click: (event) -> target = event.target while target -- cgit v1.2.3 From 1d7cc1e43ada7baf394f58e2f0e586a5c252f7b3 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Fri, 1 May 2015 07:02:06 +0100 Subject: Don't try and enter GrabBackFocus mode if the last click introduced focus --- content_scripts/vimium_frontend.coffee | 3 +++ 1 file changed, 3 insertions(+) (limited to 'content_scripts/vimium_frontend.coffee') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 661ea1c4..e1d7b581 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -139,6 +139,9 @@ class GrabBackFocus extends Mode handlerStack.push _name: "GrabBackFocus-pushState-monitor" click: (event) -> + # If a focusable element is focused, the user must have clicked on it. Retain focus and bail. + return true if DomUtils.isFocusable document.activeElement + target = event.target while target # Often, a link which triggers a content load and url change with javascript will also have the new -- cgit v1.2.3