import sys with open(sys.argv[1], 'r') as f: content = f.read() # Replace NoteEditor to use ref-based onChange (no re-render on keystroke) old_editor = '''const NoteEditor = memo(function NoteEditor({ content, onChange, placeholder = "Start writing..." }: { content: string; onChange: (html: string) => void; placeholder?: string }) { const editorRef = useRef(null); const [isPlaceholder, setIsPlaceholder] = useState(!content); useEffect(() => { if (editorRef.current && !editorRef.current.innerHTML) { editorRef.current.innerHTML = content || ""; } }, [content]); const handleInput = () => { const html = editorRef.current?.innerHTML || ""; setIsPlaceholder(!html || html === "
"); onChange(html); }; return (
{isPlaceholder && (
{placeholder}
)}
); });''' new_editor = '''const NoteEditor = memo(function NoteEditor({ content, onChange, placeholder = "Start writing..." }: { content: string; onChange: (html: string) => void; placeholder?: string }) { const editorRef = useRef(null); const onChangeRef = useRef(onChange); onChangeRef.current = onChange; const [isPlaceholder, setIsPlaceholder] = useState(!content); useEffect(() => { if (editorRef.current && !editorRef.current.innerHTML) { editorRef.current.innerHTML = content || ""; } }, [content]); const handleInput = useCallback(() => { const html = editorRef.current?.innerHTML || ""; setIsPlaceholder(!html || html === "
"); onChangeRef.current(html); }, []); return (
{isPlaceholder && (
{placeholder}
)}
); });''' content = content.replace(old_editor, new_editor, 1) with open(sys.argv[1], 'w') as f: f.write(content) print('Done')