(cm)
| 2332 | } |
| 2333 | |
| 2334 | function highlightWorker(cm) { |
| 2335 | var doc = cm.doc; |
| 2336 | if (doc.frontier < doc.first) doc.frontier = doc.first; |
| 2337 | if (doc.frontier >= cm.display.viewTo) return; |
| 2338 | var end = +new Date + cm.options.workTime; |
| 2339 | var state = copyState(doc.mode, getStateBefore(cm, doc.frontier)); |
| 2340 | var changedLines = []; |
| 2341 | |
| 2342 | doc.iter(doc.frontier, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function(line) { |
| 2343 | if (doc.frontier >= cm.display.viewFrom) { // Visible |
| 2344 | var oldStyles = line.styles; |
| 2345 | var highlighted = highlightLine(cm, line, state, true); |
| 2346 | line.styles = highlighted.styles; |
| 2347 | var oldCls = line.styleClasses, newCls = highlighted.classes; |
| 2348 | if (newCls) line.styleClasses = newCls; |
| 2349 | else if (oldCls) line.styleClasses = null; |
| 2350 | var ischange = !oldStyles || oldStyles.length != line.styles.length || |
| 2351 | oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass); |
| 2352 | for (var i = 0; !ischange && i < oldStyles.length; ++i) ischange = oldStyles[i] != line.styles[i]; |
| 2353 | if (ischange) changedLines.push(doc.frontier); |
| 2354 | line.stateAfter = copyState(doc.mode, state); |
| 2355 | } else { |
| 2356 | processLine(cm, line.text, state); |
| 2357 | line.stateAfter = doc.frontier % 5 == 0 ? copyState(doc.mode, state) : null; |
| 2358 | } |
| 2359 | ++doc.frontier; |
| 2360 | if (+new Date > end) { |
| 2361 | startWorker(cm, cm.options.workDelay); |
| 2362 | return true; |
| 2363 | } |
| 2364 | }); |
| 2365 | if (changedLines.length) runInOp(cm, function() { |
| 2366 | for (var i = 0; i < changedLines.length; i++) |
| 2367 | regLineChange(cm, changedLines[i], "text"); |
| 2368 | }); |
| 2369 | } |
| 2370 | |
| 2371 | // Finds the line to start with when starting a parse. Tries to |
| 2372 | // find a line with a stateAfter, so that it can start with a |
nothing calls this directly
no test coverage detected