MCPcopy Create free account
hub / github.com/ronreiter/interactive-tutorials / highlightWorker

Function highlightWorker

static/js/codemirror/codemirror.js:861–894  ·  view source on GitHub ↗
(cm)

Source from the content-addressed store, hash-verified

859 }
860
861 function highlightWorker(cm) {
862 var doc = cm.doc;
863 if (doc.frontier < doc.first) doc.frontier = doc.first;
864 if (doc.frontier >= cm.display.showingTo) return;
865 var end = +new Date + cm.options.workTime;
866 var state = copyState(doc.mode, getStateBefore(cm, doc.frontier));
867 var changed = [], prevChange;
868 doc.iter(doc.frontier, Math.min(doc.first + doc.size, cm.display.showingTo + 500), function(line) {
869 if (doc.frontier >= cm.display.showingFrom) { // Visible
870 var oldStyles = line.styles;
871 line.styles = highlightLine(cm, line, state);
872 var ischange = !oldStyles || oldStyles.length != line.styles.length;
873 for (var i = 0; !ischange && i < oldStyles.length; ++i) ischange = oldStyles[i] != line.styles[i];
874 if (ischange) {
875 if (prevChange && prevChange.end == doc.frontier) prevChange.end++;
876 else changed.push(prevChange = {start: doc.frontier, end: doc.frontier + 1});
877 }
878 line.stateAfter = copyState(doc.mode, state);
879 } else {
880 processLine(cm, line, state);
881 line.stateAfter = doc.frontier % 5 == 0 ? copyState(doc.mode, state) : null;
882 }
883 ++doc.frontier;
884 if (+new Date > end) {
885 startWorker(cm, cm.options.workDelay);
886 return true;
887 }
888 });
889 if (changed.length)
890 operation(cm, function() {
891 for (var i = 0; i < changed.length; ++i)
892 regChange(this, changed[i].start, changed[i].end);
893 })();
894 }
895
896 // Finds the line to start with when starting a parse. Tries to
897 // find a line with a stateAfter, so that it can start with a

Callers

nothing calls this directly

Calls 8

copyStateFunction · 0.85
getStateBeforeFunction · 0.85
highlightLineFunction · 0.85
processLineFunction · 0.85
startWorkerFunction · 0.85
operationFunction · 0.85
regChangeFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected