Lucas de Souza 5 роки тому
батько
коміт
33d1f8ffc4
1 змінених файлів з 39 додано та 0 видалено
  1. 39 0
      js/visualUI/text_editor.js

+ 39 - 0
js/visualUI/text_editor.js

@@ -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();
+}