diff options
author | Kristóf Marussy <marussy@mit.bme.hu> | 2021-10-02 02:11:31 +0200 |
---|---|---|
committer | Kristóf Marussy <marussy@mit.bme.hu> | 2021-10-02 02:11:31 +0200 |
commit | b834db0fd424e7ab02fcd5e509d855f2d97863bd (patch) | |
tree | b56ce9b8f752d8ca98e1d9082c63542e5dd993c1 /language-web/src/main/js/editor/EditorArea.tsx | |
parent | feat: skeleton for language to store mapping (diff) | |
download | refinery-b834db0fd424e7ab02fcd5e509d855f2d97863bd.tar.gz refinery-b834db0fd424e7ab02fcd5e509d855f2d97863bd.tar.zst refinery-b834db0fd424e7ab02fcd5e509d855f2d97863bd.zip |
perf(web): split off CodeMirror chunks
Also optimizes statis asset caching.
Diffstat (limited to 'language-web/src/main/js/editor/EditorArea.tsx')
-rw-r--r-- | language-web/src/main/js/editor/EditorArea.tsx | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/language-web/src/main/js/editor/EditorArea.tsx b/language-web/src/main/js/editor/EditorArea.tsx new file mode 100644 index 00000000..f07a0ad8 --- /dev/null +++ b/language-web/src/main/js/editor/EditorArea.tsx | |||
@@ -0,0 +1,42 @@ | |||
1 | import { observer } from 'mobx-react-lite'; | ||
2 | import React, { useRef } from 'react'; | ||
3 | |||
4 | import { useRootStore } from '../RootStore'; | ||
5 | |||
6 | export const EditorArea = observer(() => { | ||
7 | const { editorStore } = useRootStore(); | ||
8 | const { CodeMirror } = editorStore.chunk || {}; | ||
9 | const fallbackTextarea = useRef<HTMLTextAreaElement>(null); | ||
10 | |||
11 | if (!CodeMirror) { | ||
12 | return ( | ||
13 | <textarea | ||
14 | value={editorStore.value} | ||
15 | onChange={(e) => editorStore.updateValue(e.target.value)} | ||
16 | ref={fallbackTextarea} | ||
17 | className={`problem-fallback-editor cm-s-${editorStore.codeMirrorTheme}`} | ||
18 | > | ||
19 | </textarea> | ||
20 | ); | ||
21 | } | ||
22 | |||
23 | const textarea = fallbackTextarea.current; | ||
24 | if (textarea) { | ||
25 | editorStore.setInitialSelection( | ||
26 | textarea.selectionStart, | ||
27 | textarea.selectionEnd, | ||
28 | document.activeElement === textarea, | ||
29 | ); | ||
30 | } | ||
31 | |||
32 | return ( | ||
33 | <CodeMirror | ||
34 | value={editorStore.value} | ||
35 | options={editorStore.codeMirrorOptions} | ||
36 | editorDidMount={(editor) => editorStore.editorDidMount(editor)} | ||
37 | editorWillUnmount={() => editorStore.editorWillUnmount()} | ||
38 | onBeforeChange={(_editor, _data, value) => editorStore.updateValue(value)} | ||
39 | onChange={() => editorStore.reportChanged()} | ||
40 | /> | ||
41 | ); | ||
42 | }); | ||