From: Anton Khorev Date: Sun, 16 Mar 2025 16:21:10 +0000 (+0300) Subject: Preserve sidebar scroll position when prepending to history X-Git-Tag: live~107^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/9880953e9191777574141adfb4fa340589c5a7a4 Preserve sidebar scroll position when prepending to history --- diff --git a/app/assets/javascripts/index/history.js b/app/assets/javascripts/index/history.js index 4264e5dce..229fdc2b6 100644 --- a/app/assets/javascripts/index/history.js +++ b/app/assets/javascripts/index/history.js @@ -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");