From: Tom Hughes Date: Wed, 16 Apr 2025 17:01:00 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/pull/5935' X-Git-Tag: live~37 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/c0b5281b305488bf1d0e109d5aa9ab66871f9deb?hp=1efa0a1f99bc86bcd7a7977edbe85a6c3dd3d064 Merge remote-tracking branch 'upstream/pull/5935' --- diff --git a/app/assets/javascripts/index/history-changesets-layer.js b/app/assets/javascripts/index/history-changesets-layer.js index eafa2f715..97d28ffb2 100644 --- a/app/assets/javascripts/index/history-changesets-layer.js +++ b/app/assets/javascripts/index/history-changesets-layer.js @@ -116,8 +116,10 @@ OSM.HistoryChangesetsLayer = L.FeatureGroup.extend({ const changeset = this._changesets.get(id); if (!changeset) return; - changeset.sidebarRelativePosition = state; - this._updateChangesetStyle(changeset); + if (changeset.sidebarRelativePosition !== state) { + changeset.sidebarRelativePosition = state; + this._updateChangesetStyle(changeset); + } }, getLayerId: function (layer) { diff --git a/app/assets/javascripts/index/history.js b/app/assets/javascripts/index/history.js index 8a3ba28ae..d1bcb20a1 100644 --- a/app/assets/javascripts/index/history.js +++ b/app/assets/javascripts/index/history.js @@ -38,6 +38,7 @@ OSM.History = function (map) { if (!window.IntersectionObserver) return; let keepInitialLocation = true; + let itemsInViewport = $(); changesetIntersectionObserver = new IntersectionObserver((entries) => { let closestTargetToTop, @@ -49,15 +50,16 @@ OSM.History = function (map) { const id = $(entry.target).data("changeset")?.id; if (entry.isIntersecting) { + itemsInViewport = itemsInViewport.add(entry.target); if (id) changesetsLayer.setChangesetSidebarRelativePosition(id, 0); continue; + } else { + itemsInViewport = itemsInViewport.not(entry.target); } const distanceToTop = entry.rootBounds.top - entry.boundingClientRect.bottom; const distanceToBottom = entry.boundingClientRect.top - entry.rootBounds.bottom; - if (id) changesetsLayer.setChangesetSidebarRelativePosition(id, distanceToTop >= 0 ? 1 : -1); - if (distanceToTop >= 0 && distanceToTop < closestDistanceToTop) { closestDistanceToTop = distanceToTop; closestTargetToTop = entry.target; @@ -68,6 +70,15 @@ OSM.History = function (map) { } } + itemsInViewport.first().prevAll().each(function () { + const id = $(this).data("changeset")?.id; + if (id) changesetsLayer.setChangesetSidebarRelativePosition(id, 1); + }); + itemsInViewport.last().nextAll().each(function () { + const id = $(this).data("changeset")?.id; + if (id) changesetsLayer.setChangesetSidebarRelativePosition(id, -1); + }); + changesetsLayer.reorderChangesets(); if (keepInitialLocation) {