Skip to content

Commit 72aaf05

Browse files
Tweak philc#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 philc#3119, the scroller was also being reset when the tab gained the focus.) Based on a suggestion from @marcotc.
1 parent 256547a commit 72aaf05

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

content_scripts/scroller.coffee

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ activatedElement = null
99
# https://github.com/philc/vimium/pull/2168#issuecomment-236488091
1010

1111
getScrollingElement = ->
12-
specialScrollingElement() ? document.scrollingElement ? document.body
12+
getSpecialScrollingElement() ? document.scrollingElement ? document.body
1313

1414
# Return 0, -1 or 1: the sign of the argument.
1515
# NOTE(smblott; 2014/12/17) We would like to use Math.sign(). However, according to this site
@@ -239,7 +239,6 @@ CoreScroller =
239239
# Scroller contains the two main scroll functions which are used by clients.
240240
Scroller =
241241
init: ->
242-
activatedElement = null
243242
handlerStack.push
244243
_name: 'scroller/active-element'
245244
DOMActivate: (event) -> handlerStack.alwaysContinueBubbling ->
@@ -249,6 +248,10 @@ Scroller =
249248
# yet implemented by Chrome.
250249
activatedElement = event.deepPath?[0] ? event.path?[0] ? event.target
251250
CoreScroller.init()
251+
@reset()
252+
253+
reset: ->
254+
activatedElement = null
252255

253256
# scroll the active element in :direction by :amount * :factor.
254257
# :factor is needed because :amount can take on string values, which scrollBy converts to element dimensions.
@@ -310,7 +313,7 @@ Scroller =
310313
element = findScrollableElement element, "x", amount, 1
311314
CoreScroller.scroll element, "x", amount, false
312315

313-
specialScrollingElement = ->
316+
getSpecialScrollingElement = ->
314317
selector = specialScrollingElementMap[window.location.host]
315318
if selector
316319
document.querySelector selector

content_scripts/vimium_frontend.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ checkIfEnabledForUrl = do ->
297297
{isEnabledForUrl, passKeys, frameIsFocused, isFirefox} = response
298298
Utils.isFirefox = -> isFirefox
299299
installModes() unless normalMode
300-
Scroller.init() # TODO hack to bust Scroller.activatedElement caching
301300
normalMode.setPassKeys passKeys
302301
# Hide the HUD if we're not enabled.
303302
HUD.hide true, false unless isEnabledForUrl
@@ -308,6 +307,7 @@ checkIfEnabledForUrl = do ->
308307
# When we're informed by the background page that a URL in this tab has changed, we check if we have the
309308
# correct enabled state (but only if this frame has the focus).
310309
checkEnabledAfterURLChange = forTrusted ->
310+
Scroller.reset() # The URL changing feels like navigation to the user, so reset the scroller (see #3119).
311311
checkIfEnabledForUrl() if windowIsFocused()
312312

313313
# If we are in the help dialog iframe, then HelpDialog is already defined with the necessary functions.

0 commit comments

Comments
 (0)