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 · 3 comments · Fixed by #3825
Closed

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

yihui opened this issue Aug 22, 2017 · 3 comments · Fixed by #3825
Labels
Milestone

Comments

@yihui
Copy link
Contributor

@yihui 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 bep added the Enhancement label Aug 22, 2017
@bep

This comment has been minimized.

Copy link
Member

@bep 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

This comment has been minimized.

Copy link
Member

@bep 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

This comment has been minimized.

Copy link
Contributor Author

@yihui 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 in #3825 Aug 22, 2017
bep added 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.