Skip to content

Commit

Permalink
add syntax highlighting to codemirror
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodingwizard committed Dec 18, 2023
1 parent f54774b commit 49811ad
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/components/editor/CodemirrorEditor/CodemirrorEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import ReactCodeMirror from '@uiw/react-codemirror';
import { vscodeDark } from '@uiw/codemirror-theme-vscode';
import { githubLight } from '@uiw/codemirror-theme-github';
import { cpp } from '@codemirror/lang-cpp';
import { java } from '@codemirror/lang-java';
import { python } from '@codemirror/lang-python';
import { EditorProps } from '../MonacoEditor/monaco-editor-types';
import * as Y from 'yjs';

Expand All @@ -25,9 +27,23 @@ export const CodemirrorEditor = (props: EditorProps): JSX.Element => {
}, [props.yjsInfo]);

const extensions = useMemo(() => {
if (!yCollabExtension) return [cpp()];
return [cpp(), yCollabExtension];
}, [yCollabExtension]);
let extensions = [];
if (yCollabExtension) {
extensions.push(yCollabExtension);
}
if (props.language && props.language !== 'plaintext') {
if (props.language === 'cpp') {
extensions.push(cpp());
} else if (props.language === 'java') {
extensions.push(java());
} else if (props.language === 'python') {
extensions.push(python());
} else {
console.error('Unknown language: ' + props.language);
}
}
return extensions;
}, [props.language, yCollabExtension]);

return (
<ReactCodeMirror
Expand Down

0 comments on commit 49811ad

Please sign in to comment.