feat: support edit code
This commit is contained in:
parent
9dfdc8683d
commit
30ab9e384a
@ -246,6 +246,7 @@ function App() {
|
|||||||
<CodeMirror
|
<CodeMirror
|
||||||
code={generatedCode}
|
code={generatedCode}
|
||||||
editorTheme={settings.editorTheme}
|
editorTheme={settings.editorTheme}
|
||||||
|
onCodeChange={setGeneratedCode}
|
||||||
/>
|
/>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|||||||
@ -15,9 +15,10 @@ import { html } from "@codemirror/lang-html";
|
|||||||
interface Props {
|
interface Props {
|
||||||
code: string;
|
code: string;
|
||||||
editorTheme: string;
|
editorTheme: string;
|
||||||
|
onCodeChange: (code: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function CodeMirror({ code, editorTheme }: Props) {
|
function CodeMirror({ code, editorTheme, onCodeChange }: Props) {
|
||||||
const ref = useRef<HTMLDivElement>(null);
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
const view = useRef<EditorView | null>(null);
|
const view = useRef<EditorView | null>(null);
|
||||||
|
|
||||||
@ -42,6 +43,11 @@ function CodeMirror({ code, editorTheme }: Props) {
|
|||||||
html(),
|
html(),
|
||||||
selectedTheme,
|
selectedTheme,
|
||||||
EditorView.lineWrapping,
|
EditorView.lineWrapping,
|
||||||
|
EditorView.updateListener.of(update => {
|
||||||
|
if (update.changes) {
|
||||||
|
onCodeChange(view.current?.state.doc.toString() || "");
|
||||||
|
}
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
parent: ref.current as Element,
|
parent: ref.current as Element,
|
||||||
@ -69,3 +75,4 @@ function CodeMirror({ code, editorTheme }: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default CodeMirror;
|
export default CodeMirror;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user