]> git.openstreetmap.org Git - rails.git/commitdiff
Preserve sidebar scroll position when prepending to history
authorAnton Khorev <tony29@yandex.ru>
Sun, 16 Mar 2025 16:21:10 +0000 (19:21 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sun, 16 Mar 2025 16:42:08 +0000 (19:42 +0300)
app/assets/javascripts/index/history.js

index 4264e5dce34c8501518d1c8937588b3d6ddd52ea..229fdc2b609901b672a72a03769c47d71ba4f777 100644 (file)
@@ -48,6 +48,9 @@ OSM.History = function (map) {
   }
 
   function displayMoreChangesets(div, html) {
+    const sidebar = $("#sidebar")[0];
+    const previousScrollHeightMinusTop = sidebar.scrollHeight - sidebar.scrollTop;
+
     const oldList = $("#sidebar_content .changesets ol");
 
     div.replaceWith(html);
@@ -57,6 +60,9 @@ OSM.History = function (map) {
       prevNewList.next(".changeset_more").remove();
       prevNewList.children().prependTo(oldList);
       prevNewList.remove();
+
+      // restore scroll position only if prepending
+      sidebar.scrollTop = sidebar.scrollHeight - previousScrollHeightMinusTop;
     }
 
     const nextNewList = oldList.nextAll("ol");