MCPcopy Create free account
hub / github.com/breck7/scroll / highlightWorker

Function highlightWorker

external/.scrollLibs.js:5765–5821  ·  view source on GitHub ↗
(cm)

Source from the content-addressed store, hash-verified

5763 }
5764
5765 function highlightWorker(cm) {
5766 var doc = cm.doc
5767 if (doc.highlightFrontier >= cm.display.viewTo) {
5768 return
5769 }
5770 var end = +new Date() + cm.options.workTime
5771 var context = getContextBefore(cm, doc.highlightFrontier)
5772 var changedLines = []
5773
5774 doc.iter(context.line, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function (line) {
5775 if (context.line >= cm.display.viewFrom) {
5776 // Visible
5777 var oldStyles = line.styles
5778 var resetState = line.text.length > cm.options.maxHighlightLength ? copyState(doc.mode, context.state) : null
5779 var highlighted = highlightLine(cm, line, context, true)
5780 if (resetState) {
5781 context.state = resetState
5782 }
5783 line.styles = highlighted.styles
5784 var oldCls = line.styleClasses,
5785 newCls = highlighted.classes
5786 if (newCls) {
5787 line.styleClasses = newCls
5788 } else if (oldCls) {
5789 line.styleClasses = null
5790 }
5791 var ischange = !oldStyles || oldStyles.length != line.styles.length || (oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass))
5792 for (var i = 0; !ischange && i < oldStyles.length; ++i) {
5793 ischange = oldStyles[i] != line.styles[i]
5794 }
5795 if (ischange) {
5796 changedLines.push(context.line)
5797 }
5798 line.stateAfter = context.save()
5799 context.nextLine()
5800 } else {
5801 if (line.text.length <= cm.options.maxHighlightLength) {
5802 processLine(cm, line.text, context)
5803 }
5804 line.stateAfter = context.line % 5 == 0 ? context.save() : null
5805 context.nextLine()
5806 }
5807 if (+new Date() > end) {
5808 startWorker(cm, cm.options.workDelay)
5809 return true
5810 }
5811 })
5812 doc.highlightFrontier = context.line
5813 doc.modeFrontier = Math.max(doc.modeFrontier, context.line)
5814 if (changedLines.length) {
5815 runInOp(cm, function () {
5816 for (var i = 0; i < changedLines.length; i++) {
5817 regLineChange(cm, changedLines[i], "text")
5818 }
5819 })
5820 }
5821 }
5822

Callers

nothing calls this directly

Calls 9

getContextBeforeFunction · 0.85
copyStateFunction · 0.85
highlightLineFunction · 0.85
processLineFunction · 0.85
startWorkerFunction · 0.85
runInOpFunction · 0.85
regLineChangeFunction · 0.85
minMethod · 0.80
maxMethod · 0.80

Tested by

no test coverage detected