diff options
| author | Stephen Blott | 2018-09-04 11:03:32 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2018-09-04 11:03:32 +0100 | 
| commit | 72aaf054201755f837ba84f26a4d74846a81ffba (patch) | |
| tree | 0156b09af378e1d6dace4d8b015f2fccf69bd260 | |
| parent | 256547a940b5ac182ba014add8f1fd234baa3a65 (diff) | |
| download | vimium-72aaf054201755f837ba84f26a4d74846a81ffba.tar.bz2 | |
Tweak #3119.
1. Use verb phrase for function name.
2. Add `Scroller.reset()` method.  This *only* resets the activated element.
3. Reset the scroller only if the URL has changed.  (Previously, in #3119, the scroller was also being reset when the tab gained the focus.)
   Based on a suggestion from @marcotc.
| -rw-r--r-- | content_scripts/scroller.coffee | 9 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 2 | 
2 files changed, 7 insertions, 4 deletions
| diff --git a/content_scripts/scroller.coffee b/content_scripts/scroller.coffee index 19bf91cf..94a0d4f1 100644 --- a/content_scripts/scroller.coffee +++ b/content_scripts/scroller.coffee @@ -9,7 +9,7 @@ activatedElement = null  # https://github.com/philc/vimium/pull/2168#issuecomment-236488091  getScrollingElement = -> -  specialScrollingElement() ? document.scrollingElement ? document.body +  getSpecialScrollingElement() ? document.scrollingElement ? document.body  # Return 0, -1 or 1: the sign of the argument.  # NOTE(smblott; 2014/12/17) We would like to use Math.sign().  However, according to this site @@ -239,7 +239,6 @@ CoreScroller =  # Scroller contains the two main scroll functions which are used by clients.  Scroller =    init: -> -    activatedElement = null      handlerStack.push        _name: 'scroller/active-element'        DOMActivate: (event) -> handlerStack.alwaysContinueBubbling -> @@ -249,6 +248,10 @@ Scroller =          # yet implemented by Chrome.          activatedElement = event.deepPath?[0] ? event.path?[0] ? event.target      CoreScroller.init() +    @reset() + +  reset: -> +    activatedElement = null    # scroll the active element in :direction by :amount * :factor.    # :factor is needed because :amount can take on string values, which scrollBy converts to element dimensions. @@ -310,7 +313,7 @@ Scroller =          element = findScrollableElement element, "x", amount, 1          CoreScroller.scroll element, "x", amount, false -specialScrollingElement = -> +getSpecialScrollingElement = ->    selector = specialScrollingElementMap[window.location.host]    if selector      document.querySelector selector diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index e93a7ad9..6fa118cf 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -297,7 +297,6 @@ checkIfEnabledForUrl = do ->      {isEnabledForUrl, passKeys, frameIsFocused, isFirefox} = response      Utils.isFirefox = -> isFirefox      installModes() unless normalMode -    Scroller.init() # TODO hack to bust Scroller.activatedElement caching      normalMode.setPassKeys passKeys      # Hide the HUD if we're not enabled.      HUD.hide true, false unless isEnabledForUrl @@ -308,6 +307,7 @@ checkIfEnabledForUrl = do ->  # When we're informed by the background page that a URL in this tab has changed, we check if we have the  # correct enabled state (but only if this frame has the focus).  checkEnabledAfterURLChange = forTrusted -> +  Scroller.reset() # The URL changing feels like navigation to the user, so reset the scroller (see #3119).    checkIfEnabledForUrl() if windowIsFocused()  # If we are in the help dialog iframe, then HelpDialog is already defined with the necessary functions. | 
