trying other way of managing monaco editor

This commit is contained in:
2024-09-30 13:42:22 -06:00
parent a51a968aea
commit e65b4d8627
8 changed files with 83 additions and 25 deletions

View File

@@ -0,0 +1,49 @@
"use client";
import React, { useRef } from "react";
import { editor } from "monaco-editor/esm/vs/editor/editor.api";
import Editor from "@monaco-editor/react";
export default function InnerMonacoEditorOther({
value,
onChange,
}: {
value: string;
onChange: (value: string) => void; // must be memoized
}) {
const editorRef = useRef<editor.IStandaloneCodeEditor | null>(null);
function handleEditorDidMount(editor: editor.IStandaloneCodeEditor) {
editorRef.current = editor;
editor.onDidChangeModelContent((e) => {
onChange(editorRef.current?.getModel()?.getValue() ?? "");
});
}
return (
<>
<Editor
height="100%"
options={{
value: value,
tabSize: 3,
minimap: {
enabled: false,
},
lineNumbers: "off",
wordWrap: "on",
automaticLayout: true,
fontFamily: "Roboto-mono",
fontSize: 16,
padding: {
top: 10,
},
}}
defaultLanguage="markdown"
theme="vs-dark"
defaultValue={value}
onMount={handleEditorDidMount}
/>
</>
);
}