Skip to content
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

Scaladoc: scaladoc anchor navigation can't handle some same page links #17182

Closed
KacperFKorban opened this issue Mar 30, 2023 · 3 comments · Fixed by #17910
Closed

Scaladoc: scaladoc anchor navigation can't handle some same page links #17182

KacperFKorban opened this issue Mar 30, 2023 · 3 comments · Fixed by #17910
Assignees

Comments

@KacperFKorban
Copy link
Member

Compiler version

main

Description

In some cases, scaladoc can't properly scroll to anchors that are on the same page. In those cases, it takes several tries for scaladoc to scroll the entire way.
e.g.

scaladoc-anchor-same-page-oopsie

Expectation

Scaladoc should always be able to scroll to anchors.

@KacperFKorban KacperFKorban changed the title Scaladoc: scaladoc anchor navications can't handle some same page links Scaladoc: scaladoc anchor navigation can't handle some same page links Mar 30, 2023
@Dedelweiss Dedelweiss self-assigned this Jun 5, 2023
@Dedelweiss
Copy link
Contributor

Dedelweiss commented Jun 6, 2023

Hello, from what I noticed during my test, the problem comes from the fact that the anchor does not remain in the URL. After some research, I found this javascript that replaces the anchor with an empty string.
In scaladoc/resources/dotty_res/scripts/ux.js:

if (lastEntry.isIntersecting) {
  window.location.hash = "";
  removeAllHighlights();
  const id = getIdOfElement(lastEntry);

  getTocListElement(id).parentElement.classList.toggle("active");
}

So from what I see, this if statement checks if the last entry in entries is intersecting with the window, indicating that it is visible on the screen. If that's the case, the code performs the following actions:

  • It resets the window's anchor.

  • It calls the removeAllHighlights function to remove any existing highlights from the table of contents elements and put the element where we are in active

So I know what the purpose of this if is but when I delete it, I don't see any change (and it works better).

Before:

Screen.Recording.2023-06-06.at.10.12.13.mov

After:

Screenshot 2023-06-06 at 10 14 34
Screen.Recording.2023-06-06.at.10.19.45.mov

The issue is not present on Firefox.

@julienrf
Copy link
Contributor

julienrf commented Jun 6, 2023

@KacperFKorban Which browser do you use? On my Firefox I can’t reproduce the issue.

@KacperFKorban
Copy link
Member Author

@julienrf I use Chrome. I see that the issue is reproducible, based on the previous comment.

@Florian3k Can you take a look at @Dedelweiss suggestion?

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

Successfully merging a pull request may close this issue.

4 participants