MCPcopy
hub / github.com/witheve/Eve / highlightWorker

Function highlightWorker

src/codemirror.js:2445–2481  ·  view source on GitHub ↗
(cm)

Source from the content-addressed store, hash-verified

2443 }
2444
2445 function highlightWorker(cm) {
2446 var doc = cm.doc;
2447 if (doc.frontier < doc.first) doc.frontier = doc.first;
2448 if (doc.frontier >= cm.display.viewTo) return;
2449 var end = +new Date + cm.options.workTime;
2450 var state = copyState(doc.mode, getStateBefore(cm, doc.frontier));
2451 var changedLines = [];
2452
2453 doc.iter(doc.frontier, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function(line) {
2454 if (doc.frontier >= cm.display.viewFrom) { // Visible
2455 var oldStyles = line.styles, tooLong = line.text.length > cm.options.maxHighlightLength;
2456 var highlighted = highlightLine(cm, line, tooLong ? copyState(doc.mode, state) : state, true);
2457 line.styles = highlighted.styles;
2458 var oldCls = line.styleClasses, newCls = highlighted.classes;
2459 if (newCls) line.styleClasses = newCls;
2460 else if (oldCls) line.styleClasses = null;
2461 var ischange = !oldStyles || oldStyles.length != line.styles.length ||
2462 oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass);
2463 for (var i = 0; !ischange && i < oldStyles.length; ++i) ischange = oldStyles[i] != line.styles[i];
2464 if (ischange) changedLines.push(doc.frontier);
2465 line.stateAfter = tooLong ? state : copyState(doc.mode, state);
2466 } else {
2467 if (line.text.length <= cm.options.maxHighlightLength)
2468 processLine(cm, line.text, state);
2469 line.stateAfter = doc.frontier % 5 == 0 ? copyState(doc.mode, state) : null;
2470 }
2471 ++doc.frontier;
2472 if (+new Date > end) {
2473 startWorker(cm, cm.options.workDelay);
2474 return true;
2475 }
2476 });
2477 if (changedLines.length) runInOp(cm, function() {
2478 for (var i = 0; i < changedLines.length; i++)
2479 regLineChange(cm, changedLines[i], "text");
2480 });
2481 }
2482
2483 // Finds the line to start with when starting a parse. Tries to
2484 // find a line with a stateAfter, so that it can start with a

Callers

nothing calls this directly

Calls 6

getStateBeforeFunction · 0.85
highlightLineFunction · 0.85
processLineFunction · 0.85
startWorkerFunction · 0.85
runInOpFunction · 0.85
regLineChangeFunction · 0.85

Tested by

no test coverage detected