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

Let hugo server --navigateToChanged maintain the scroll position if possible #3824

Closed
yihui opened this issue Aug 22, 2017 · 4 comments · Fixed by #3825
Closed

Let hugo server --navigateToChanged maintain the scroll position if possible #3824

yihui opened this issue Aug 22, 2017 · 4 comments · Fixed by #3825

Comments

@yihui
Copy link
Contributor

yihui commented Aug 22, 2017

When I'm currently viewing a page of which the source Markdown file is being edited, I wish the scroll position of this page in the browser could be maintained when --navigateToChanged is enabled for hugo server. That is, if Hugo is about to navigate to the same page as the current page in the browser, location.reload() should be called instead of location.href = "NEW_LOCATION" in JS. I'm not sure if that is possible with Hugo, or it requires upstream support from LiveReload.

@bep
Copy link
Member

bep commented Aug 22, 2017

location.reload()

I'm too lazy to look it up: Is this a standard JS method supported by all browsers?

If so, this should be possible to fix on the Hugo side.

@bep bep added this to the v0.27 milestone Aug 22, 2017
@bep
Copy link
Member

bep commented Aug 22, 2017

If someone wants to fix this, here is the location:

https://github.com/gohugoio/hugo/blob/master/livereload/livereload.go#L117

@yihui
Copy link
Contributor Author

yihui commented Aug 22, 2017

Yes, location.reload() is fairly standard: https://developer.mozilla.org/en-US/docs/Web/API/Location/reload

I just submitted the PR #3825. Thanks!

@bep bep closed this as completed in #3825 Aug 22, 2017
bep pushed a commit that referenced this issue Aug 22, 2017
This fixes #3824: when the current pathname is the same as the one to be loaded, just call location.reload() so that the current scroll position can be preserved, instead of assigning to location.href, which will cause the scroll position to be lost.
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants