feat(web): don't scroll to visible assets (#20729)

The timeline has been quite aggressive with scrolling to assets, even if they
were right in the middle of the page. If the asset is visible, then we
shouldn't scroll to it. It's really confusing when assets jump around after
being viewed.
This commit is contained in:
Thomas 2025-08-06 22:31:37 +01:00 committed by GitHub
parent bbfff64927
commit 1193a23282
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -149,12 +149,28 @@
return height; return height;
}; };
const assetIsVisible = (assetTop: number): boolean => {
if (!element) {
return false;
}
const { clientHeight, scrollTop } = element;
return assetTop >= scrollTop && assetTop < scrollTop + clientHeight;
};
const scrollToAssetId = async (assetId: string) => { const scrollToAssetId = async (assetId: string) => {
const monthGroup = await timelineManager.findMonthGroupForAsset(assetId); const monthGroup = await timelineManager.findMonthGroupForAsset(assetId);
if (!monthGroup) { if (!monthGroup) {
return false; return false;
} }
const height = getAssetHeight(assetId, monthGroup); const height = getAssetHeight(assetId, monthGroup);
// If the asset is already visible, then don't scroll.
if (assetIsVisible(height)) {
return true;
}
scrollTo(height); scrollTo(height);
updateSlidingWindow(); updateSlidingWindow();
return true; return true;