Skip to content

Commit f86e611

Browse files
Merge branch 'marcotc--new-reddit-scroll'
2 parents 299c368 + 72aaf05 commit f86e611

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

content_scripts/scroller.coffee

Lines changed: 14 additions & 10 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-
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
@@ -248,6 +248,10 @@ Scroller =
248248
# yet implemented by Chrome.
249249
activatedElement = event.deepPath?[0] ? event.path?[0] ? event.target
250250
CoreScroller.init()
251+
@reset()
252+
253+
reset: ->
254+
activatedElement = null
251255

252256
# scroll the active element in :direction by :amount * :factor.
253257
# :factor is needed because :amount can take on string values, which scrollBy converts to element dimensions.
@@ -309,15 +313,15 @@ Scroller =
309313
element = findScrollableElement element, "x", amount, 1
310314
CoreScroller.scroll element, "x", amount, false
311315

312-
# Hack to make expanded tweets scrollable on Twitter (See #3045).
313-
if DomUtils.isTopFrame() and window.location.host == "twitter.com"
314-
for method in ["scrollTo", "scrollBy"]
315-
do ->
316-
func = Scroller[method]
317-
Scroller[method] = ->
318-
element = document.querySelector "div.permalink-container div.permalink[role=main]"
319-
activatedElement = element ? getScrollingElement()
320-
func arguments...
316+
getSpecialScrollingElement = ->
317+
selector = specialScrollingElementMap[window.location.host]
318+
if selector
319+
document.querySelector selector
320+
321+
specialScrollingElementMap =
322+
'twitter.com': 'div.permalink-container div.permalink[role=main]'
323+
'reddit.com': '#overlayScrollContainer'
324+
'new.reddit.com': '#overlayScrollContainer'
321325

322326
root = exports ? (window.root ?= {})
323327
root.Scroller = Scroller

content_scripts/vimium_frontend.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ checkIfEnabledForUrl = do ->
307307
# When we're informed by the background page that a URL in this tab has changed, we check if we have the
308308
# correct enabled state (but only if this frame has the focus).
309309
checkEnabledAfterURLChange = forTrusted ->
310+
Scroller.reset() # The URL changing feels like navigation to the user, so reset the scroller (see #3119).
310311
checkIfEnabledForUrl() if windowIsFocused()
311312

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

0 commit comments

Comments
 (0)