openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

mode_state.min.js (621B)


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