|
1 | | -import React, { useReducer } from "react"; |
| 1 | +import React from "react"; |
2 | 2 | import { useEffect, useRef, useState } from "react"; |
3 | 3 | import Editor, { Monaco } from "@monaco-editor/react"; |
4 | 4 | import type { editor } from "monaco-editor"; |
@@ -52,8 +52,6 @@ const FileEditor = ({ |
52 | 52 | extraSnippets?: ExtraSnippets; |
53 | 53 | }) => { |
54 | 54 | const theme = useTheme(); |
55 | | - const [, forceUpdate] = useReducer(x => x + 1, 0); |
56 | | - const [lang, setLang] = useState(language); |
57 | 55 |
|
58 | 56 | const editorRef = useRef<editor.IStandaloneCodeEditor | null>(null); |
59 | 57 | const monacoRef = useRef<Monaco | null>(null); |
@@ -167,6 +165,9 @@ const FileEditor = ({ |
167 | 165 | "editor.background": theme.palette.background, |
168 | 166 | }, |
169 | 167 | }); |
| 168 | + console.log( |
| 169 | + monaco.editor.getEditors()[0].getModel()?.getLanguageId() |
| 170 | + ) |
170 | 171 | }; |
171 | 172 |
|
172 | 173 | const handleEditorMount = async ( |
@@ -272,10 +273,6 @@ const FileEditor = ({ |
272 | 273 | setFontSize(Math.max(10, 14 + zoomLevel * 2)); |
273 | 274 | }, [zoomLevel]); |
274 | 275 |
|
275 | | - useEffect(() => { |
276 | | - setLang(language) |
277 | | - }, [language]); |
278 | | - |
279 | 276 | // Code Analysis (with pylint) |
280 | 277 | useEffect(() => { |
281 | 278 | if ( |
@@ -322,22 +319,27 @@ const FileEditor = ({ |
322 | 319 | ); |
323 | 320 | }, [fileContent]); |
324 | 321 |
|
| 322 | + console.log(language) |
| 323 | + |
325 | 324 | return ( |
326 | | - <Editor |
327 | | - width="100%" |
328 | | - height="100%" |
329 | | - defaultLanguage={"python"} |
330 | | - defaultValue="" |
331 | | - language={lang} |
332 | | - value={fileContent} |
333 | | - theme={`${theme.monacoTheme}-theme`} |
334 | | - onChange={(newContent: any) => { |
335 | | - setFileContent(newContent); |
336 | | - }} |
337 | | - options={editorOptions} |
338 | | - beforeMount={handleEditorDidMount} |
339 | | - onMount={handleEditorMount} |
340 | | - /> |
| 325 | + <> |
| 326 | + {language && ( |
| 327 | + <Editor |
| 328 | + width="100%" |
| 329 | + height="100%" |
| 330 | + defaultValue="" |
| 331 | + language={language} |
| 332 | + value={fileContent} |
| 333 | + theme={`${theme.monacoTheme}-theme`} |
| 334 | + onChange={(newContent: any) => { |
| 335 | + setFileContent(newContent); |
| 336 | + }} |
| 337 | + options={editorOptions} |
| 338 | + beforeMount={handleEditorDidMount} |
| 339 | + onMount={handleEditorMount} |
| 340 | + /> |
| 341 | + )} |
| 342 | + </> |
341 | 343 | ); |
342 | 344 | }; |
343 | 345 |
|
|
0 commit comments