livereload: Maintain the scroll position if possible
authorYihui Xie <xie@yihui.name>
Tue, 22 Aug 2017 15:29:09 +0000 (10:29 -0500)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 22 Aug 2017 18:26:33 +0000 (20:26 +0200)
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.

livereload/livereload.go

index a5da891fc4ab66a13cb7d01fcf5a5b2ed72b50d3..74702175f3a175bc360cbadffc479a69642c7cf7 100644 (file)
@@ -122,7 +122,12 @@ HugoReload.prototype.reload = function(path, options) {
        }
 
        path = path.substring(prefix.length);
-       window.location.href = path;
+
+       if (window.location.pathname === path) {
+               window.location.reload();
+       } else {
+               window.location.href = path;
+       }
 
        return true;
 };