mode_state.js 621 B

12345678910111213141516171819202122
  1. import { getMode } from "../modes.js"
  2. import { startWorker } from "./highlight_worker.js"
  3. import { regChange } from "./view_tracking.js"
  4. // Used to get the editor into a consistent state again when options change.
  5. export function loadMode(cm) {
  6. cm.doc.mode = getMode(cm.options, cm.doc.modeOption)
  7. resetModeState(cm)
  8. }
  9. export function resetModeState(cm) {
  10. cm.doc.iter(line => {
  11. if (line.stateAfter) line.stateAfter = null
  12. if (line.styles) line.styles = null
  13. })
  14. cm.doc.modeFrontier = cm.doc.highlightFrontier = cm.doc.first
  15. startWorker(cm, 100)
  16. cm.state.modeGen++
  17. if (cm.curOp) regChange(cm)
  18. }