From a9d1127afd77a0c16722d820e8c32d2fc9fa2c41 Mon Sep 17 00:00:00 2001 From: evan188199-tech Date: Thu, 10 Sep 2026 23:44:53 +0800 Subject: [PATCH] fix(watching): clamp transcript alignment to middle 50% and respect reduced motion (#1351) Co-authored-by: XZH --- web/components/watching/WatchingPane.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/web/components/watching/WatchingPane.tsx b/web/components/watching/WatchingPane.tsx index ff6f6e303..62217fa57 100644 --- a/web/components/watching/WatchingPane.tsx +++ b/web/components/watching/WatchingPane.tsx @@ -180,13 +180,23 @@ export function WatchingPane({ onClose }: { onClose(): void }) { const list = transcriptListRef.current const activeRow = list?.querySelector('[data-active-cue="true"]') if (!list || !activeRow) return - const rowTop = + const rowCenter = activeRow.getBoundingClientRect().top - list.getBoundingClientRect().top + list.scrollTop - list.clientHeight / 2 + activeRow.clientHeight / 2 - list.scrollTo({ top: Math.max(0, rowTop), behavior: 'smooth' }) + // Clamp the active row's centre to the middle 50% of the viewport so it + // sits near the caption overlay without jumping to the exact midpoint. + const upperMargin = list.clientHeight * 0.25 + const lowerMargin = list.clientHeight * 0.75 + const clampedTop = Math.min(Math.max(0, rowCenter - upperMargin), list.scrollHeight - list.clientHeight) + const targetTop = Math.max(0, Math.min(clampedTop, rowCenter - lowerMargin)) + const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches + list.scrollTo({ + top: targetTop, + behavior: prefersReducedMotion ? 'instant' : 'smooth', + }) }, [cue, followTranscript, tab]) const submit = async (providerOverride?: 'youtube') => {