Optimize scroll handling in App.tsx

This commit is contained in:
2026-02-01 03:28:05 +01:00
parent 1c9af949b4
commit 9936fd2c0f

View File

@@ -437,12 +437,25 @@ export default function App() {
visibleRange.start
]);
const handleTextareaScroll = useCallback((event: React.UIEvent<HTMLTextAreaElement>) => {
if (!showLineNumbersActive) return;
if (lineNumbersRef.current) {
lineNumbersRef.current.scrollTop = event.currentTarget.scrollTop;
const scheduleUpdateVisibleRange = useCallback(() => {
if (scrollRafRef.current) {
cancelAnimationFrame(scrollRafRef.current);
}
}, [showLineNumbersActive]);
scrollRafRef.current = requestAnimationFrame(() => {
updateVisibleRange();
});
}, [updateVisibleRange]);
const handleTextareaScroll = useCallback(
(event: React.UIEvent<HTMLTextAreaElement>) => {
if (!showLineNumbersActive) return;
if (lineNumbersRef.current) {
lineNumbersRef.current.scrollTop = event.currentTarget.scrollTop;
}
scheduleUpdateVisibleRange();
},
[scheduleUpdateVisibleRange, showLineNumbersActive]
);
useEffect(() => {
if (!showLineNumbersActive) return;