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