fixup 85a5702f: refactor; properly clear renderLintReportNow

This commit is contained in:
tophf 2017-09-03 19:36:33 +03:00
parent 13908a60a4
commit 0c205df108

View File

@ -229,20 +229,22 @@ function updateLintReport(cm, delay) {
} }
function updateLintReportInternal(scope, {postponeNewIssues} = {}) { function updateLintReportInternal(scope, {postponeNewIssues} = {}) {
scope = scope ? [scope] : editors; const {changed, fixedSome} = (scope ? [scope] : editors).reduce(process, {});
let changed = false; if (changed) {
let fixedOldIssues = false; const renderNow = editors.last.state.renderLintReportNow =
const clipString = (str, limit) => !postponeNewIssues || fixedSome || editors.last.state.renderLintReportNow;
str.length <= limit ? str : str.substr(0, limit) + '...'; debounce(renderLintReport, renderNow ? 0 : CodeMirror.defaults.lintReportDelay, true);
scope.forEach(cm => { }
function process(result, cm) {
const lintState = cm.state.lint || {}; const lintState = cm.state.lint || {};
const oldMarkers = lintState.markedLast || new Map(); const oldMarkers = lintState.stylusMarkers || new Map();
const newMarkers = lintState.markedLast = new Map(); const newMarkers = lintState.stylusMarkers = new Map();
const marked = lintState.marked || {}; const oldText = (lintState.body || {}).textContentCached || '';
const activeLine = cm.getCursor().line; const activeLine = cm.getCursor().line;
if (marked.length) { const body = !(lintState.marked || {}).length ? {} : $element({
const body = $element({tag: 'tbody', tag: 'tbody',
appendChild: marked.map(mark => { appendChild: lintState.marked.map(mark => {
const info = mark.__annotation; const info = mark.__annotation;
const {line, ch} = info.from; const {line, ch} = info.from;
const isActiveLine = line === activeLine; const isActiveLine = line === activeLine;
@ -253,10 +255,12 @@ function updateLintReportInternal(scope, {postponeNewIssues} = {}) {
oldMarkers.delete(pos); oldMarkers.delete(pos);
} }
newMarkers.set(pos, message); newMarkers.set(pos, message);
return $element({tag: 'tr', return $element({
tag: 'tr',
className: info.severity, className: info.severity,
appendChild: [ appendChild: [
$element({tag: 'td', $element({
tag: 'td',
attributes: {role: 'severity'}, attributes: {role: 'severity'},
dataset: {rule: info.rule}, dataset: {rule: info.rule},
appendChild: $element({ appendChild: $element({
@ -272,21 +276,15 @@ function updateLintReportInternal(scope, {postponeNewIssues} = {}) {
}); });
}) })
}); });
const text = body.textContentCached = body.textContent; body.textContentCached = body.textContent || '';
if (text !== ((lintState.body || {}).textContentCached || '')) { lintState.body = body.textContentCached && body;
lintState.body = body; result.changed |= oldText !== body.textContentCached;
changed = true; result.fixedSome |= lintState.reportDisplayed && oldMarkers.size;
} return result;
}
fixedOldIssues |= lintState.reportDisplayed && oldMarkers.size;
});
if (changed) {
if (!postponeNewIssues || fixedOldIssues || editors.last.state.renderLintReportNow) {
editors.last.state.renderLintReportNow = false;
renderLintReport(true);
} else {
debounce(renderLintReport, CodeMirror.defaults.lintReportDelay, true);
} }
function clipString(str, limit) {
return str.length <= limit ? str : str.substr(0, limit) + '...';
} }
} }
@ -297,6 +295,7 @@ function renderLintReport(someBlockChanged) {
const newContent = content.cloneNode(false); const newContent = content.cloneNode(false);
let issueCount = 0; let issueCount = 0;
editors.forEach((cm, index) => { editors.forEach((cm, index) => {
cm.state.renderLintReportNow = false;
const lintState = cm.state.lint || {}; const lintState = cm.state.lint || {};
const body = lintState.body; const body = lintState.body;
if (!body) { if (!body) {