From: Tom Hughes Date: Wed, 16 Apr 2025 17:03:24 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/pull/5936' X-Git-Tag: live~60 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/e72b6e6612e9a68e69b1d5f9f99260287410cc4f?hp=7601146d111a455fa87bcbf59eca06bad81f034e Merge remote-tracking branch 'upstream/pull/5936' --- diff --git a/app/assets/javascripts/index/history-changesets-layer.js b/app/assets/javascripts/index/history-changesets-layer.js index 4d011bb0d..1ada28637 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) {