text_editor.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import * as CodeMirror from "codemirror";
  2. import "codemirror/addon/edit/closebrackets";
  3. import "codemirror/addon/edit/matchbrackets";
  4. // import "codemirror/addon/hint/show-hint";
  5. // import "codemirror/addon/hint/anyword-hint";
  6. import "codemirror/addon/selection/active-line";
  7. import "./../util/editorMode2"
  8. let codeEditor = null;
  9. export function initTextEditor (element) {
  10. let id = element;
  11. if (element[0] == '#') {
  12. id = element.substring(1);
  13. }
  14. codeEditor = CodeMirror.fromTextArea(document.getElementById(id), {
  15. value: "",
  16. mode: "text/x-ivprog",
  17. indentUnit: 4,
  18. lineNumbers: true,
  19. matchBrackets: true,
  20. autoCloseBrackets: true,
  21. fixedGutter: true,
  22. styleActiveLine: true,
  23. readOnly: true
  24. });
  25. }
  26. export function disable (flag) {
  27. codeEditor.setOption("readOnly", flag);
  28. updateEditor();
  29. }
  30. export function updateEditor () {
  31. codeEditor.refresh();
  32. }
  33. export function setCode (code) {
  34. codeEditor.setValue(code);
  35. }
  36. export function getCode () {
  37. return codeEditor.getValue();
  38. }