MCPcopy
hub / github.com/csev/py4e / highlightWorker

Function highlightWorker

tools/pythonauto/static/codemirrorepl/codemirrorepl.js:2008–2050  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2006 });
2007 }
2008 function highlightWorker() {
2009 var end = +new Date + options.workTime;
2010 var foundWork = work.length;
2011 while (work.length) {
2012 if (!getLine(showingFrom).stateAfter) var task = showingFrom;
2013 else var task = work.pop();
2014 if (task >= doc.size) continue;
2015 var start = findStartLine(task), state = start && getLine(start-1).stateAfter;
2016 if (state) state = copyState(mode, state);
2017 else state = startState(mode);
2018
2019 var unchanged = 0, compare = mode.compareStates, realChange = false,
2020 i = start, bail = false;
2021 doc.iter(i, doc.size, function(line) {
2022 var hadState = line.stateAfter;
2023 if (+new Date > end) {
2024 work.push(i);
2025 startWorker(options.workDelay);
2026 if (realChange) changes.push({from: task, to: i + 1});
2027 return (bail = true);
2028 }
2029 var changed = line.highlight(mode, state, options.tabSize);
2030 if (changed) realChange = true;
2031 line.stateAfter = copyState(mode, state);
2032 var done = null;
2033 if (compare) {
2034 var same = hadState && compare(hadState, state);
2035 if (same != Pass) done = !!same;
2036 }
2037 if (done == null) {
2038 if (changed !== false || !hadState) unchanged = 0;
2039 else if (++unchanged > 3 && (!mode.indent || mode.indent(hadState, "") == mode.indent(state, "")))
2040 done = true;
2041 }
2042 if (done) return true;
2043 ++i;
2044 });
2045 if (bail) return;
2046 if (realChange) changes.push({from: task, to: i + 1});
2047 }
2048 if (foundWork && options.onHighlightComplete)
2049 options.onHighlightComplete(instance);
2050 }
2051 function startWorker(time) {
2052 if (!work.length) return;
2053 highlight.set(time, operation(highlightWorker));

Callers

nothing calls this directly

Calls 6

compareFunction · 0.85
getLineFunction · 0.70
findStartLineFunction · 0.70
copyStateFunction · 0.70
startStateFunction · 0.70
startWorkerFunction · 0.70

Tested by

no test coverage detected