fixup 85a5702f: refactor; properly clear renderLintReportNow
This commit is contained in:
parent
13908a60a4
commit
0c205df108
113
edit/lint.js
113
edit/lint.js
|
@ -229,64 +229,62 @@ 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;
|
|
||||||
let fixedOldIssues = false;
|
|
||||||
const clipString = (str, limit) =>
|
|
||||||
str.length <= limit ? str : str.substr(0, limit) + '...';
|
|
||||||
scope.forEach(cm => {
|
|
||||||
const lintState = cm.state.lint || {};
|
|
||||||
const oldMarkers = lintState.markedLast || new Map();
|
|
||||||
const newMarkers = lintState.markedLast = new Map();
|
|
||||||
const marked = lintState.marked || {};
|
|
||||||
const activeLine = cm.getCursor().line;
|
|
||||||
if (marked.length) {
|
|
||||||
const body = $element({tag: 'tbody',
|
|
||||||
appendChild: marked.map(mark => {
|
|
||||||
const info = mark.__annotation;
|
|
||||||
const {line, ch} = info.from;
|
|
||||||
const isActiveLine = line === activeLine;
|
|
||||||
const pos = isActiveLine ? 'cursor' : (line + ',' + ch);
|
|
||||||
const title = clipString(info.message, 1000) + `\n(${info.rule})`;
|
|
||||||
const message = clipString(info.message, 100);
|
|
||||||
if (isActiveLine || oldMarkers[pos] === message) {
|
|
||||||
oldMarkers.delete(pos);
|
|
||||||
}
|
|
||||||
newMarkers.set(pos, message);
|
|
||||||
return $element({tag: 'tr',
|
|
||||||
className: info.severity,
|
|
||||||
appendChild: [
|
|
||||||
$element({tag: 'td',
|
|
||||||
attributes: {role: 'severity'},
|
|
||||||
dataset: {rule: info.rule},
|
|
||||||
appendChild: $element({
|
|
||||||
className: 'CodeMirror-lint-marker-' + info.severity,
|
|
||||||
textContent: info.severity,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
$element({tag: 'td', attributes: {role: 'line'}, textContent: line + 1}),
|
|
||||||
$element({tag: 'td', attributes: {role: 'sep'}, textContent: ':'}),
|
|
||||||
$element({tag: 'td', attributes: {role: 'col'}, textContent: ch + 1}),
|
|
||||||
$element({tag: 'td', attributes: {role: 'message'}, textContent: message, title}),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
})
|
|
||||||
});
|
|
||||||
const text = body.textContentCached = body.textContent;
|
|
||||||
if (text !== ((lintState.body || {}).textContentCached || '')) {
|
|
||||||
lintState.body = body;
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fixedOldIssues |= lintState.reportDisplayed && oldMarkers.size;
|
|
||||||
});
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
if (!postponeNewIssues || fixedOldIssues || editors.last.state.renderLintReportNow) {
|
const renderNow = editors.last.state.renderLintReportNow =
|
||||||
editors.last.state.renderLintReportNow = false;
|
!postponeNewIssues || fixedSome || editors.last.state.renderLintReportNow;
|
||||||
renderLintReport(true);
|
debounce(renderLintReport, renderNow ? 0 : CodeMirror.defaults.lintReportDelay, true);
|
||||||
} else {
|
}
|
||||||
debounce(renderLintReport, CodeMirror.defaults.lintReportDelay, true);
|
|
||||||
}
|
function process(result, cm) {
|
||||||
|
const lintState = cm.state.lint || {};
|
||||||
|
const oldMarkers = lintState.stylusMarkers || new Map();
|
||||||
|
const newMarkers = lintState.stylusMarkers = new Map();
|
||||||
|
const oldText = (lintState.body || {}).textContentCached || '';
|
||||||
|
const activeLine = cm.getCursor().line;
|
||||||
|
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;
|
||||||
|
const pos = isActiveLine ? 'cursor' : (line + ',' + ch);
|
||||||
|
const title = clipString(info.message, 1000) + `\n(${info.rule})`;
|
||||||
|
const message = clipString(info.message, 100);
|
||||||
|
if (isActiveLine || oldMarkers[pos] === message) {
|
||||||
|
oldMarkers.delete(pos);
|
||||||
|
}
|
||||||
|
newMarkers.set(pos, message);
|
||||||
|
return $element({
|
||||||
|
tag: 'tr',
|
||||||
|
className: info.severity,
|
||||||
|
appendChild: [
|
||||||
|
$element({
|
||||||
|
tag: 'td',
|
||||||
|
attributes: {role: 'severity'},
|
||||||
|
dataset: {rule: info.rule},
|
||||||
|
appendChild: $element({
|
||||||
|
className: 'CodeMirror-lint-marker-' + info.severity,
|
||||||
|
textContent: info.severity,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
$element({tag: 'td', attributes: {role: 'line'}, textContent: line + 1}),
|
||||||
|
$element({tag: 'td', attributes: {role: 'sep'}, textContent: ':'}),
|
||||||
|
$element({tag: 'td', attributes: {role: 'col'}, textContent: ch + 1}),
|
||||||
|
$element({tag: 'td', attributes: {role: 'message'}, textContent: message, title}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
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);
|
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) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user