|
@@ -0,0 +1,39 @@
|
|
|
+import * as CodeMirror from "codemirror";
|
|
|
+import "codemirror/addon/edit/closebrackets";
|
|
|
+import "codemirror/addon/edit/matchbrackets";
|
|
|
+import "codemirror/addon/edit/matchbrackets";
|
|
|
+import "codemirror/addon/selection/active-line";
|
|
|
+
|
|
|
+let codeEditor = null;
|
|
|
+
|
|
|
+export function initTextEditor (element) {
|
|
|
+ let id = element;
|
|
|
+ if (element[0] == '#') {
|
|
|
+ id = element.substring(1);
|
|
|
+ }
|
|
|
+ codeEditor = CodeMirror.fromTextArea(document.getElementById(id), {
|
|
|
+ value: "",
|
|
|
+ lineNumbers: true,
|
|
|
+ matchBrackets: true,
|
|
|
+ autoCloseBrackets: true,
|
|
|
+ fixedGutter: true,
|
|
|
+ styleActiveLine: true
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+export function disable (flag) {
|
|
|
+ codeEditor.setOption({readOnly: flag})
|
|
|
+ updateEditor();
|
|
|
+}
|
|
|
+
|
|
|
+export function updateEditor () {
|
|
|
+ codeEditor.refresh();
|
|
|
+}
|
|
|
+
|
|
|
+export function setCode (code) {
|
|
|
+ codeEditor.setValue(code);
|
|
|
+}
|
|
|
+
|
|
|
+export function getCode () {
|
|
|
+ return codeEditor.getValue();
|
|
|
+}
|