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

Comments

Projects
None yet
2 participants
@yihui
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 bep added the Enhancement label Aug 22, 2017

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Aug 22, 2017

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@bep

bep Aug 22, 2017

Member

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

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

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 added a commit to yihui/hugo that referenced this issue Aug 22, 2017

livereload: Maintain the scroll position if possible
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.
@yihui

This comment has been minimized.

Show comment
Hide comment
@yihui

yihui Aug 22, 2017

Contributor

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

I just submitted the PR #3825. Thanks!

Contributor

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

livereload: Maintain the scroll position if possible
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