From 9880953e9191777574141adfb4fa340589c5a7a4 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 16 Mar 2025 19:21:10 +0300 Subject: [PATCH] Preserve sidebar scroll position when prepending to history --- app/assets/javascripts/index/history.js | 6 ++++++ 1 file changed, 6 insertions(+) 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"); -- 2.39.5