- return CodeMirror.fromTextArea(textArea, {
- mode: getMode(mode, textArea.value),
- lineNumbers: true,
- lineWrapping: false,
- theme: getTheme(),
- });
+ const content = textArea.value;
+ const config = {
+ parent: textArea.parentNode,
+ doc: content,
+ extensions: [
+ ...editor(textArea.parentElement),
+ EditorView.updateListener.of((v) => {
+ if (v.docChanged) {
+ textArea.value = v.state.doc.toString();
+ }
+ }),
+ ],
+ };
+
+ // Create editor view, hide original input
+ const ev = createView(config);
+ setMode(ev, mode, content);
+ textArea.style.display = 'none';
+
+ return ev;