diff --git a/src/renderer/features/lyrics/synchronized-lyrics.tsx b/src/renderer/features/lyrics/synchronized-lyrics.tsx index 79ab034ee..5f0f1887e 100644 --- a/src/renderer/features/lyrics/synchronized-lyrics.tsx +++ b/src/renderer/features/lyrics/synchronized-lyrics.tsx @@ -95,6 +95,7 @@ export const SynchronizedLyrics = ({ const scrollTimeoutRef = useRef>(null); const containerRef = useRef(null); const programmaticScrollRef = useRef(false); + const programmaticScrollTimeoutRef = useRef>(null); const getCurrentLyric = (timeInMs: number) => { const activeLyrics = lyricRef.current; @@ -178,9 +179,6 @@ export const SynchronizedLyrics = ({ if (followRef.current && !userScrollingRef.current) { programmaticScrollRef.current = true; doc?.scroll({ behavior: 'smooth', top: offsetTop }); - setTimeout(() => { - programmaticScrollRef.current = false; - }, 600); } if (index !== lyricRef.current!.length - 1) { @@ -287,6 +285,14 @@ export const SynchronizedLyrics = ({ const handleScroll = () => { // Ignore programmatic scrolls (auto-scroll) if (programmaticScrollRef.current) { + if (programmaticScrollTimeoutRef.current) { + clearTimeout(programmaticScrollTimeoutRef.current); + } + + programmaticScrollTimeoutRef.current = setTimeout(() => { + programmaticScrollRef.current = false; + }, 150); + return; } @@ -309,6 +315,10 @@ export const SynchronizedLyrics = ({ if (scrollTimeoutRef.current) { clearTimeout(scrollTimeoutRef.current); } + + if (programmaticScrollTimeoutRef.current) { + clearTimeout(programmaticScrollTimeoutRef.current); + } }; }, []);