diff options
Diffstat (limited to 'content_scripts/vimium_frontend.coffee')
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 02e6c9ee..e1d7b581 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -133,6 +133,32 @@ 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. This fixes issue #1622. +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 + # 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 |
