Preserve scroll across required library refreshes

This commit is contained in:
xmarre
2026-08-19 09:17:17 +02:00
parent afd3c6b8fb
commit 4e9dc2457a
+18
View File
@@ -49,3 +49,21 @@ export function cardIntentInsertionIndex(items, draggedId, targetId) {
export function materializationNeedsLibraryRefresh(payload) {
return Array.isArray(payload?.moved) && payload.moved.length > 0
}
export function libraryRefreshScrollRestore(
view,
savedScrollTop,
liveScrollTop,
clientWidth,
clientHeight
) {
const normalizedView = String(view ?? '')
if (!normalizedView) return null
const visible = Number(clientWidth) > 0 && Number(clientHeight) > 0
const live = Number(liveScrollTop)
const saved = Number(savedScrollTop)
const scrollTop = visible && Number.isFinite(live)
? live
: (Number.isFinite(saved) ? saved : 0)
return { view: normalizedView, scrollTop: Math.max(0, scrollTop) }
}