From f8772a05157bb7fdfadedb140bcef85942eb7f6f Mon Sep 17 00:00:00 2001 From: Abi Raja Date: Tue, 28 Nov 2023 09:49:57 -0500 Subject: [PATCH] format CodeMirror --- frontend/src/components/CodeMirror.tsx | 52 ++++++++++++++------------ 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/frontend/src/components/CodeMirror.tsx b/frontend/src/components/CodeMirror.tsx index 1459dac..c1dba0e 100644 --- a/frontend/src/components/CodeMirror.tsx +++ b/frontend/src/components/CodeMirror.tsx @@ -22,28 +22,32 @@ interface Props { function CodeMirror({ code, editorTheme, onCodeChange }: Props) { const ref = useRef(null); const view = useRef(null); - const editorState = useMemo(() => EditorState.create({ - extensions: [ - history(), - keymap.of([ - ...defaultKeymap, - indentWithTab, - { key: "Mod-z", run: undo, preventDefault: true }, - { key: "Mod-Shift-z", run: redo, preventDefault: true }, - ]), - lineNumbers(), - bracketMatching(), - html(), - editorTheme === EditorTheme.ESPRESSO ? espresso : cobalt, - EditorView.lineWrapping, - EditorView.updateListener.of((update: ViewUpdate) => { - if (update.docChanged) { - const updatedCode = update.state.doc.toString(); - onCodeChange(updatedCode); - } + const editorState = useMemo( + () => + EditorState.create({ + extensions: [ + history(), + keymap.of([ + ...defaultKeymap, + indentWithTab, + { key: "Mod-z", run: undo, preventDefault: true }, + { key: "Mod-Shift-z", run: redo, preventDefault: true }, + ]), + lineNumbers(), + bracketMatching(), + html(), + editorTheme === EditorTheme.ESPRESSO ? espresso : cobalt, + EditorView.lineWrapping, + EditorView.updateListener.of((update: ViewUpdate) => { + if (update.docChanged) { + const updatedCode = update.state.doc.toString(); + onCodeChange(updatedCode); + } + }), + ], }), - ], - }), [editorTheme]); + [editorTheme] + ); useEffect(() => { view.current = new EditorView({ state: editorState, @@ -67,9 +71,11 @@ function CodeMirror({ code, editorTheme, onCodeChange }: Props) { }, [code]); return ( -
+
); } export default CodeMirror; -