Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use monaco-editor for code display #173

Merged
merged 12 commits into from
Nov 13, 2023
Prev Previous commit
Next Next commit
Autofold on initialization
carbonrobot committed Nov 10, 2023
commit 7978a58165c57ae73781cd8d77166621e6581ac5
13 changes: 7 additions & 6 deletions packages/webui/src/components/MonacoEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Editor, EditorProps, Monaco } from '@monaco-editor/react';
import { Editor, EditorProps, OnMount } from '@monaco-editor/react';
import colors from 'tailwindcss/colors';

export type MonacoEditorProps = Pick<EditorProps, 'value' | 'language'>;
@@ -13,11 +13,7 @@ const editorOptions: EditorProps['options'] = {
lineNumbers: 'off',
};

export default function MonacoEditor({ value, language }: MonacoEditorProps) {
return <Editor value={value} language={language} options={editorOptions} onMount={setEditorTheme} />;
}

function setEditorTheme(_: any, monaco: Monaco) {
const setEditorTheme: OnMount = (editor, monaco) => {
monaco.editor.defineTheme('envy', {
base: 'vs',
inherit: true,
@@ -28,4 +24,9 @@ function setEditorTheme(_: any, monaco: Monaco) {
rules: [],
});
monaco.editor.setTheme('envy');
editor.trigger('fold', 'editor.foldLevel4', {});
};

export default function MonacoEditor({ value, language }: MonacoEditorProps) {
return <Editor value={value} language={language} options={editorOptions} onMount={setEditorTheme} />;
}