Skip to content

Handle scrolling on Reddit redesign #3119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 4, 2018

Conversation

marcotc
Copy link
Contributor

@marcotc marcotc commented Aug 31, 2018

This PR adds support for scrolling the through the new Reddit post popups, introduced during the ongoing Reddit redesign effort.

Before scrolling with j and k would scroll the background, instead of the foreground article:

before

With the changes in this PR, it will now scroll the popup post correctly:

after

Implementation notes

Unfortunately document.scrollingElement will always return the document's body, meaning we never reach our fallback codes that could handle edge-cases like this.

The solution implemented in this PR is ad-hoc, which is subpar to say the least. It is based on a recent similar fix for Twitter.

If this solution is acceptable for now, I'm willing to refactor these two ad-hoc to reduce code duplication.
I could move them into an external configuration file instead, as the only variables are the URLs affected, and how to find the scrollable element.

@smblott-github
Copy link
Collaborator

This is more or less what I was going to try to get to. Reddit is sufficiently important to warrant a site-specific hack.

If this solution is acceptable for now, I'm willing to refactor these two ad-hoc to reduce code duplication.

Yes. Please refactor to eliminate duplication. Perhaps with configuration via a dictionary mapping hostnames to CSS. No need to go so far as an external configuration file just yet. It's enough to have the code isolated from the real scrolling logic at the bottom of scroller.coffee.

@marcotc
Copy link
Contributor Author

marcotc commented Sep 1, 2018

Thank you for the review @smblott-github, I'll make changes to implement your feedback.

@marcotc
Copy link
Contributor Author

marcotc commented Sep 4, 2018

@smblott-github I took at stab at refactoring it and pushed a few changes.

One thing that I'm not satisfied with is how I had to bust the value of activatedElement.
Because activatedElement is cached globally inside scroller.coffee, it ends up storing the first value it sees, and only refreshes when you navigate to another page.
Unfortunately Reddit uses history manipulation to move between from list of posts, to each post itself.

I found some code around vimium_frontend.coffee:checkIfEnabledForUrl() that gets triggered on history manipulation. That code actually calls installModes() the first time it runs, which initializes the Scroller, but on further history updates, it gets skipped.

It seems to me that any scrolling state should be reset when history changes, so my thought was to refactor scroller.coffee to make the whole scrolling logic be created anew on history change, but that's a rather large endeavour. This solution is my preference, but I don't like the possible sizable refactoring required for it.

Another option is to create a vimium_frontend.coffee:installModes() function, that gets called like so:

 checkIfEnabledForUrl = do ->
   Frame.addEventListener "isEnabledForUrl", (response) ->
    # ...
    if normalMode
      refreshModes()
    else
      installModes()

That function would contain only Scroller.init() currently. (Or even better, Scroller.refresh()) .

@smblott-github smblott-github merged commit 256547a into philc:master Sep 4, 2018
smblott-github added a commit that referenced this pull request Sep 4, 2018
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.
@smblott-github
Copy link
Collaborator

Thanks, @marcotc.

It seems to me that any scrolling state should be reset when history changes...

That's an interesting observation. You're right.

I made a couple of tweaks (72aaf05). Let me know if you spot a mistake.

Once again, thanks.

@marcotc
Copy link
Contributor Author

marcotc commented Sep 4, 2018

Hi @smblott-github, thank you for merging this.
Seems fine to me, thanks again for all the help!

Szczyp pushed a commit to Szczyp/vimium that referenced this pull request Oct 25, 2018
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.
@devanshuDesai
Copy link

Still facing this issue with j and k scrolling as of December 9, 2018.

@marcotc
Copy link
Contributor Author

marcotc commented Dec 11, 2018

Confirmed regression, almost certain Reddit has changed their layout.

@tehp
Copy link

tehp commented Dec 27, 2018

Bump, also experiencing this issue.

@kitaev
Copy link

kitaev commented Mar 4, 2019

Doesn't work for me with Firefox 65.0.2 on Linux. Vimium version 1.64.3.

@sooriravindra
Copy link

Doesn't work on Chrome Version 73.0.3683.103 (Official Build) (64-bit)

@dseeni
Copy link

dseeni commented Apr 24, 2019

same here as well, using the 74.0.3729.108 build of chorme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants