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

TOC navigations should be recorded in history #1248

Open
ShaopengLin opened this issue Nov 13, 2024 · 7 comments
Open

TOC navigations should be recorded in history #1248

ShaopengLin opened this issue Nov 13, 2024 · 7 comments

Comments

@ShaopengLin
Copy link
Collaborator

ShaopengLin commented Nov 13, 2024

Currently, the TOC #42 navigations do not go through the Qt system and use Javascript to scroll directly. It would be great to have an in-page history, where the history records those actions but sends them to Javascript for scrolling instead of refreshing the current page to the URL.

Note that if a page is refreshed, all DOM states are also reset, which is not what we want. This is the reason why we cannot use setUr to navigate to TOC entries.

@kelson42 kelson42 added this to the 2.5.0 milestone Dec 24, 2024
@Jinash-Rouniyar
Copy link

I'd like to work on this issue. My approach would be to use history.pushState() instead of just scrolling, allowing in-page navigation to be recorded in history and listen for popstate events to restore correct TOC position when using back/forward navigation. Any feedback or suggestions?

@kelson42
Copy link
Collaborator

@Jinash-Rouniyar Thank you for your comment. Your appraoch sounds worth a try at least. @ShaopengLin Any feedback?

@ShaopengLin
Copy link
Collaborator Author

ShaopengLin commented Feb 13, 2025

@Jinash-Rouniyar Thats sounds good, though I have a concern: One obvious caveat you need to be aware of is that users can switch websites, which reloads the webpage. History inside Javascript might not be persistent.

If it is indeed not persistent, I would recommend using the Qt WebEngine history, as all user actions stems from the Qt side. You can do special handling for TOC navigations and signal to Javascript page the scroll location. In addition, less race condition to worry about :)

@Jinash-Rouniyar
Copy link

@kelson42 I've implemented the Qt WebEngine history approach as suggested by @ShaopengLin, and the in-page navigation works smoothly even when the users switch sites, however, there are two issues I need to address 1) When a TOC item is clicked, the code pushes a state that differs only by the hash(anchor), so this change isn't considered full navigation by the browser, and I need to use alt + right/left to activate back/forward navigation on the page. 2) The TOC UI does not update on back/forward navigation. Any suggestions?

@kelson42
Copy link
Collaborator

@Jinash-Rouniyar Nice, create a PR, put it in draft and fix the two problem left.

@ShaopengLin
Copy link
Collaborator Author

@Jinash-Rouniyar

  1. I am not exactly sure what it means by full navigation. Could you share a video for reference or expand it in more detaul? The forward and back navigation shortcuts and actions are controlled by our Qt code, so you should be able to perform specialized handling of these scenarios?

  2. In the control for forward and backward action, emit a signal to update TOC UI.

@Jinash-Rouniyar
Copy link

@kelson42 I've resolved the TOC UI update and shared a video for @ShaopengLin to review the other issue I have been facing. https://www.loom.com/share/0827d2d2abbc4f6c9c4cc6a9978c3b44?sid=018da29b-fb5c-4aa4-89cc-5a9738a0b77d
I'll go ahead and create a draft pull request as you suggested. Thanks.

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.

3 participants