MCPcopy Create free account
hub / github.com/TruthHun/BookStack / highlightWorker

Function highlightWorker

static/mergely/lib/codemirror.js:2437–2473  ·  view source on GitHub ↗
(cm)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected