MCPcopy
hub / github.com/hokein/electron-sample-apps / highlightWorker

Function highlightWorker

mini-code-editor/cm/lib/codemirror.js:1808–1850  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1806 });
1807 }
1808 function highlightWorker() {
1809 var end = +new Date + options.workTime;
1810 var foundWork = work.length;
1811 while (work.length) {
1812 if (!getLine(showingFrom).stateAfter) var task = showingFrom;
1813 else var task = work.pop();
1814 if (task >= doc.size) continue;
1815 var start = findStartLine(task), state = start && getLine(start-1).stateAfter;
1816 if (state) state = copyState(mode, state);
1817 else state = startState(mode);
1818
1819 var unchanged = 0, compare = mode.compareStates, realChange = false,
1820 i = start, bail = false;
1821 doc.iter(i, doc.size, function(line) {
1822 var hadState = line.stateAfter;
1823 if (+new Date > end) {
1824 work.push(i);
1825 startWorker(options.workDelay);
1826 if (realChange) changes.push({from: task, to: i + 1});
1827 return (bail = true);
1828 }
1829 var changed = line.highlight(mode, state, options.tabSize);
1830 if (changed) realChange = true;
1831 line.stateAfter = copyState(mode, state);
1832 var done = null;
1833 if (compare) {
1834 var same = hadState && compare(hadState, state);
1835 if (same != Pass) done = !!same;
1836 }
1837 if (done == null) {
1838 if (changed !== false || !hadState) unchanged = 0;
1839 else if (++unchanged > 3 && (!mode.indent || mode.indent(hadState, "") == mode.indent(state, "")))
1840 done = true;
1841 }
1842 if (done) return true;
1843 ++i;
1844 });
1845 if (bail) return;
1846 if (realChange) changes.push({from: task, to: i + 1});
1847 }
1848 if (foundWork && options.onHighlightComplete)
1849 options.onHighlightComplete(instance);
1850 }
1851 function startWorker(time) {
1852 if (!work.length) return;
1853 highlight.set(time, operation(highlightWorker));

Callers

nothing calls this directly

Calls 5

getLineFunction · 0.85
findStartLineFunction · 0.85
copyStateFunction · 0.85
startStateFunction · 0.85
startWorkerFunction · 0.85

Tested by

no test coverage detected