diff options
Diffstat (limited to 'renderer/src/components/DocumentPane.tsx')
| -rw-r--r-- | renderer/src/components/DocumentPane.tsx | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/renderer/src/components/DocumentPane.tsx b/renderer/src/components/DocumentPane.tsx index c5f456c..f5368b3 100644 --- a/renderer/src/components/DocumentPane.tsx +++ b/renderer/src/components/DocumentPane.tsx | |||
| @@ -5,6 +5,7 @@ import { EditorState } from "@codemirror/state"; | |||
| 5 | import { EditorView, keymap, lineNumbers, highlightActiveLine, drawSelection } from "@codemirror/view"; | 5 | import { EditorView, keymap, lineNumbers, highlightActiveLine, drawSelection } from "@codemirror/view"; |
| 6 | import { markdown } from "@codemirror/lang-markdown"; | 6 | import { markdown } from "@codemirror/lang-markdown"; |
| 7 | import { languages } from "@codemirror/language-data"; | 7 | import { languages } from "@codemirror/language-data"; |
| 8 | import { syntaxHighlighting, defaultHighlightStyle } from "@codemirror/language"; | ||
| 8 | import { defaultKeymap, history, historyKeymap } from "@codemirror/commands"; | 9 | import { defaultKeymap, history, historyKeymap } from "@codemirror/commands"; |
| 9 | import { oneDark } from "@codemirror/theme-one-dark"; | 10 | import { oneDark } from "@codemirror/theme-one-dark"; |
| 10 | import type { Phase } from "../types"; | 11 | import type { Phase } from "../types"; |
| @@ -15,16 +16,19 @@ interface DocumentPaneProps { | |||
| 15 | phase: Phase; | 16 | phase: Phase; |
| 16 | disabled: boolean; | 17 | disabled: boolean; |
| 17 | showOnboarding?: boolean; | 18 | showOnboarding?: boolean; |
| 19 | theme: "dark" | "light"; | ||
| 18 | } | 20 | } |
| 19 | 21 | ||
| 20 | function MarkdownEditor({ | 22 | function MarkdownEditor({ |
| 21 | content, | 23 | content, |
| 22 | onChange, | 24 | onChange, |
| 23 | disabled, | 25 | disabled, |
| 26 | theme, | ||
| 24 | }: { | 27 | }: { |
| 25 | content: string; | 28 | content: string; |
| 26 | onChange: (content: string) => void; | 29 | onChange: (content: string) => void; |
| 27 | disabled: boolean; | 30 | disabled: boolean; |
| 31 | theme: "dark" | "light"; | ||
| 28 | }) { | 32 | }) { |
| 29 | const editorRef = useRef<HTMLDivElement>(null); | 33 | const editorRef = useRef<HTMLDivElement>(null); |
| 30 | const viewRef = useRef<EditorView | null>(null); | 34 | const viewRef = useRef<EditorView | null>(null); |
| @@ -47,7 +51,7 @@ function MarkdownEditor({ | |||
| 47 | history(), | 51 | history(), |
| 48 | keymap.of([...defaultKeymap, ...historyKeymap]), | 52 | keymap.of([...defaultKeymap, ...historyKeymap]), |
| 49 | markdown({ codeLanguages: languages }), | 53 | markdown({ codeLanguages: languages }), |
| 50 | oneDark, | 54 | theme === "dark" ? oneDark : syntaxHighlighting(defaultHighlightStyle), |
| 51 | updateListener, | 55 | updateListener, |
| 52 | EditorView.editable.of(!disabled), | 56 | EditorView.editable.of(!disabled), |
| 53 | EditorView.lineWrapping, | 57 | EditorView.lineWrapping, |
| @@ -81,7 +85,7 @@ function MarkdownEditor({ | |||
| 81 | view.destroy(); | 85 | view.destroy(); |
| 82 | viewRef.current = null; | 86 | viewRef.current = null; |
| 83 | }; | 87 | }; |
| 84 | }, [disabled]); | 88 | }, [disabled, theme]); |
| 85 | 89 | ||
| 86 | // Update content when it changes externally | 90 | // Update content when it changes externally |
| 87 | useEffect(() => { | 91 | useEffect(() => { |
| @@ -109,6 +113,7 @@ export function DocumentPane({ | |||
| 109 | phase, | 113 | phase, |
| 110 | disabled, | 114 | disabled, |
| 111 | showOnboarding, | 115 | showOnboarding, |
| 116 | theme, | ||
| 112 | }: DocumentPaneProps) { | 117 | }: DocumentPaneProps) { |
| 113 | const [isEditing, setIsEditing] = useState(false); | 118 | const [isEditing, setIsEditing] = useState(false); |
| 114 | 119 | ||
| @@ -211,6 +216,7 @@ export function DocumentPane({ | |||
| 211 | content={content} | 216 | content={content} |
| 212 | onChange={onChange} | 217 | onChange={onChange} |
| 213 | disabled={disabled} | 218 | disabled={disabled} |
| 219 | theme={theme} | ||
| 214 | /> | 220 | /> |
| 215 | ) : ( | 221 | ) : ( |
| 216 | <div | 222 | <div |
