]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/5935'
authorTom Hughes <tom@compton.nu>
Wed, 16 Apr 2025 17:01:00 +0000 (18:01 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 16 Apr 2025 17:01:00 +0000 (18:01 +0100)
app/assets/javascripts/index/history-changesets-layer.js
app/assets/javascripts/index/history.js

index eafa2f71502bdeb63612a4488ae032bdfb753aec..97d28ffb20f84cd280f138eb921215da8dca509d 100644 (file)
@@ -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) {
index 8a3ba28ae56646ad6cdc05a4517a59c9c28e37ac..d1bcb20a192235c5880e3c911b87e96885381dc7 100644 (file)
@@ -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) {