"use client"; import type { UIEvent } from "react"; import { useMemo, useRef } from "react"; import { highlight } from "@/lib/highlight"; type CodeEditorProps = { value: string; onChange: (value: string) => void; language?: string; ariaLabel: string; className?: string; }; export function CodeEditor({ value, onChange, language = "zero", ariaLabel, className = "", }: CodeEditorProps) { const preRef = useRef(null); const html = useMemo(() => { const trailingNewline = value.endsWith("\n") ? " " : ""; return highlight(value + trailingNewline, language); }, [value, language]); function handleScroll(event: UIEvent) { const pre = preRef.current; if (!pre) return; pre.scrollTop = event.currentTarget.scrollTop; pre.scrollLeft = event.currentTarget.scrollLeft; } return (