fix(frontend): scope synced row scrolling by group
This commit is contained in:
@@ -54,6 +54,7 @@ let syncedRowsCurrentOffset = 0
|
|||||||
let syncedRowsTargetOffset = 0
|
let syncedRowsTargetOffset = 0
|
||||||
let lastSyncedAnchorCol: number | null = null
|
let lastSyncedAnchorCol: number | null = null
|
||||||
let lastSyncedRowsAnimationAt: number | null = null
|
let lastSyncedRowsAnimationAt: number | null = null
|
||||||
|
let activeSyncedScrollGroup = DEFAULT_SYNC_SCROLL_GROUP
|
||||||
|
|
||||||
// Global metrics measured once from the first synced row. All calculations use
|
// Global metrics measured once from the first synced row. All calculations use
|
||||||
// these same values for every row to avoid per-row DOM query inconsistencies.
|
// these same values for every row to avoid per-row DOM query inconsistencies.
|
||||||
@@ -131,6 +132,13 @@ function getMetrics(group: string): ScrollMetrics | null {
|
|||||||
// the first synced row is already scrolled to. This avoids animating from 0
|
// the first synced row is already scrolled to. This avoids animating from 0
|
||||||
// every time the view is entered.
|
// every time the view is entered.
|
||||||
function initCurrentOffsetFromDOM(group: string) {
|
function initCurrentOffsetFromDOM(group: string) {
|
||||||
|
if (activeSyncedScrollGroup !== group) {
|
||||||
|
stopSyncedRowAnimation()
|
||||||
|
activeSyncedScrollGroup = group
|
||||||
|
syncedRowsCurrentOffset = 0
|
||||||
|
syncedRowsTargetOffset = 0
|
||||||
|
}
|
||||||
|
|
||||||
if (syncedRowsCurrentOffset !== 0) return
|
if (syncedRowsCurrentOffset !== 0) return
|
||||||
const rows = getSyncRowsByGroup(group)
|
const rows = getSyncRowsByGroup(group)
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
@@ -172,13 +180,19 @@ function clampRowScrollOffset(row: HTMLElement, offset: number): number {
|
|||||||
return Math.min(Math.max(offset, 0), getRowMaxScroll(row))
|
return Math.min(Math.max(offset, 0), getRowMaxScroll(row))
|
||||||
}
|
}
|
||||||
|
|
||||||
function applySyncedRowScroll(offset: number, rows: HTMLElement[] = getSyncedRows()) {
|
function applySyncedRowScroll(
|
||||||
|
offset: number,
|
||||||
|
rows: HTMLElement[] = getSyncRowsByGroup(activeSyncedScrollGroup),
|
||||||
|
) {
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
row.scrollLeft = clampRowScrollOffset(row, offset)
|
row.scrollLeft = clampRowScrollOffset(row, offset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setAllRowTails(tailPx: number, rows: HTMLElement[] = getSyncedRows()) {
|
function setAllRowTails(
|
||||||
|
tailPx: number,
|
||||||
|
rows: HTMLElement[] = getSyncRowsByGroup(activeSyncedScrollGroup),
|
||||||
|
) {
|
||||||
const value = `${Math.max(0, tailPx)}px`
|
const value = `${Math.max(0, tailPx)}px`
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
row.style.setProperty(SYNC_SCROLL_TAIL_VAR, value)
|
row.style.setProperty(SYNC_SCROLL_TAIL_VAR, value)
|
||||||
@@ -224,7 +238,7 @@ function stopSyncedRowAnimation() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function animateSyncedRows(now: number) {
|
function animateSyncedRows(now: number) {
|
||||||
const rows = getSyncedRows()
|
const rows = getSyncRowsByGroup(activeSyncedScrollGroup)
|
||||||
if (rows.length === 0) {
|
if (rows.length === 0) {
|
||||||
stopSyncedRowAnimation()
|
stopSyncedRowAnimation()
|
||||||
return
|
return
|
||||||
@@ -383,7 +397,7 @@ function handleSyncedRowResize() {
|
|||||||
resetSyncedRows(true)
|
resetSyncedRows(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
updateSyncedRowTarget(lastSyncedAnchorCol)
|
updateSyncedRowTarget(lastSyncedAnchorCol, activeRow || null)
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureElementVisibleVertically(element: HTMLElement) {
|
function ensureElementVisibleVertically(element: HTMLElement) {
|
||||||
|
|||||||
Reference in New Issue
Block a user