From 7a7e6c13c177ce72d351f6417c4456319f92b412 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sat, 31 Jan 2026 13:00:02 +0100 Subject: [PATCH] Add line number synchronization for textarea --- src/App.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/App.tsx b/src/App.tsx index 52fad35..e5d7049 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -155,6 +155,25 @@ export default function App() { const historyIconSrc = theme === "light" ? historyIconBright : historyIcon; + const lineNumbers = useMemo(() => { + const count = Math.max(body.split(" +").length, 1); + return Array.from({ length: count }, (_, index) => index + 1); + }, [body]); + + const handleTextareaScroll = useCallback((event: React.UIEvent) => { + if (!showLineNumbers) return; + if (lineNumbersRef.current) { + lineNumbersRef.current.scrollTop = event.currentTarget.scrollTop; + } + }, [showLineNumbers]); + + useEffect(() => { + if (showLineNumbers && textareaRef.current && lineNumbersRef.current) { + lineNumbersRef.current.scrollTop = textareaRef.current.scrollTop; + } + }, [showLineNumbers, body]); + const refreshTexts = useCallback(async () => { setLoadingTexts(true);