"use client"; import { useEffect, useState, useRef } from "react"; import { Button } from "@/components/ui/button"; import { Bold, Italic, Strikethrough, Underline } from "lucide-react"; import { MDXEditor } from "@mdxeditor/editor"; // Assuming react-mdx-editor or similar import DOMPurify from "isomorphic-dompurify"; export default function NewBlog() { const [text, setText] = useState(""); const [cursor, setCursor] = useState<{ line: number; column: number }>({ line: 0, column: 0, }); // Function to update the cursor position const getCursorPosition = (newText: string) => { const cursorPos = newText.length; const lines = newText.substring(0, cursorPos).split("\n"); const line = lines.length; // Current line number const column = lines[lines.length - 1].length + 1; // Current column number setCursor({ line, column }); }; const execCommand = (command: string) => { const pre = text.slice(0, cursor.column); const post = text.slice(cursor.column); setText(pre + command + post); getCursorPosition(pre + command + post); // Update cursor position after change }; // Sanitize the MDX text before rendering const sanitized = DOMPurify.sanitize(text); return (
{/* Using MDXEditor instead of a basic Textarea */} getCursorPosition(text)} markdown="ok" />
Line: {cursor.line}; Column: {cursor.column}
); }