mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-06 05:40:13 +08:00
fix(watching): clamp transcript alignment to middle 50% and respect reduced motion (#1351)
Co-authored-by: XZH <cto@xzh.ai>
This commit is contained in:
@@ -180,13 +180,23 @@ export function WatchingPane({ onClose }: { onClose(): void }) {
|
||||
const list = transcriptListRef.current
|
||||
const activeRow = list?.querySelector<HTMLButtonElement>('[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') => {
|
||||
|
||||
Reference in New Issue
Block a user