text_editor.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 { CodeEditorMode } from "./../util/editorMode2"
  8. CodeEditorMode(CodeMirror);
  9. let codeEditor = null;
  10. export function initTextEditor (element) {
  11. let id = element;
  12. if (element[0] == '#') {
  13. id = element.substring(1);
  14. }
  15. codeEditor = CodeMirror.fromTextArea(document.getElementById(id), {
  16. theme: "ttcn",
  17. value: "",
  18. mode: "text/x-ivprog",
  19. indentUnit: 4,
  20. lineNumbers: true,
  21. matchBrackets: true,
  22. autoCloseBrackets: true,
  23. fixedGutter: true,
  24. styleActiveLine: true,
  25. readOnly: true
  26. });
  27. }
  28. export function disable (flag) {
  29. codeEditor.setOption("readOnly", flag);
  30. updateEditor();
  31. }
  32. export function updateEditor () {
  33. codeEditor.refresh();
  34. }
  35. export function setCode (code) {
  36. codeEditor.setValue(code);
  37. }
  38. export function getCode () {
  39. return codeEditor.getValue();
  40. }