Update lint report immediately on load
This commit is contained in:
parent
7a7c679811
commit
f746cb1581
32
edit.js
32
edit.js
|
@ -309,7 +309,7 @@ function acmeEventListener(event) {
|
||||||
|
|
||||||
// replace given textarea with the CodeMirror editor
|
// replace given textarea with the CodeMirror editor
|
||||||
function setupCodeMirror(textarea, index) {
|
function setupCodeMirror(textarea, index) {
|
||||||
var cm = CodeMirror.fromTextArea(textarea);
|
var cm = CodeMirror.fromTextArea(textarea, {lint: null});
|
||||||
|
|
||||||
cm.on("change", indicateCodeChange);
|
cm.on("change", indicateCodeChange);
|
||||||
cm.on("blur", function(cm) {
|
cm.on("blur", function(cm) {
|
||||||
|
@ -858,29 +858,25 @@ function getEditorInSight(nearbyElement) {
|
||||||
function updateLintReport(cm, delay) {
|
function updateLintReport(cm, delay) {
|
||||||
if (delay == 0) {
|
if (delay == 0) {
|
||||||
// immediately show pending csslint messages in onbeforeunload and save
|
// immediately show pending csslint messages in onbeforeunload and save
|
||||||
update.call(cm);
|
update(cm);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (delay > 0) {
|
if (delay > 0) {
|
||||||
// give csslint some time to find the issues, e.g. 500 (1/10 of our default 5s)
|
setTimeout(cm => { cm.performLint(); update(cm) }, delay, cm);
|
||||||
// by settings its internal delay to 1ms and restoring it back later
|
return;
|
||||||
var lintOpt = editors[0].state.lint.options;
|
}
|
||||||
setTimeout((function(opt, delay) {
|
var state = cm.state.lint;
|
||||||
opt.delay = delay == 1 ? opt.delay : delay; // options object is shared between editors
|
if (!state) {
|
||||||
update(this);
|
|
||||||
}).bind(cm, lintOpt, lintOpt.delay), delay);
|
|
||||||
lintOpt.delay = 1;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// user is editing right now: postpone updating the report for the new issues (default: 500ms lint + 4500ms)
|
// user is editing right now: postpone updating the report for the new issues (default: 500ms lint + 4500ms)
|
||||||
// or update it as soon as possible (default: 500ms lint + 100ms) in case an existing issue was just fixed
|
// or update it as soon as possible (default: 500ms lint + 100ms) in case an existing issue was just fixed
|
||||||
var state = cm.state.lint;
|
|
||||||
clearTimeout(state.reportTimeout);
|
clearTimeout(state.reportTimeout);
|
||||||
state.reportTimeout = setTimeout(update.bind(cm), state.options.delay + 100);
|
state.reportTimeout = setTimeout(update, state.options.delay + 100, cm);
|
||||||
state.postponeNewIssues = delay == undefined || delay == null;
|
state.postponeNewIssues = delay == undefined || delay == null;
|
||||||
|
|
||||||
function update() { // this == cm
|
function update(cm) {
|
||||||
var scope = this ? [this] : editors;
|
var scope = cm ? [cm] : editors;
|
||||||
var changed = false;
|
var changed = false;
|
||||||
var fixedOldIssues = false;
|
var fixedOldIssues = false;
|
||||||
scope.forEach(function(cm) {
|
scope.forEach(function(cm) {
|
||||||
|
@ -939,7 +935,7 @@ function renderLintReport(someBlockChanged) {
|
||||||
var newContent = content.cloneNode(false);
|
var newContent = content.cloneNode(false);
|
||||||
var issueCount = 0;
|
var issueCount = 0;
|
||||||
editors.forEach(function(cm, index) {
|
editors.forEach(function(cm, index) {
|
||||||
if (cm.state.lint.html) {
|
if (cm.state.lint && cm.state.lint.html) {
|
||||||
var newBlock = newContent.appendChild(document.createElement("table"));
|
var newBlock = newContent.appendChild(document.createElement("table"));
|
||||||
var html = "<caption>" + label + " " + (index+1) + "</caption>" + cm.state.lint.html;
|
var html = "<caption>" + label + " " + (index+1) + "</caption>" + cm.state.lint.html;
|
||||||
newBlock.innerHTML = html;
|
newBlock.innerHTML = html;
|
||||||
|
@ -1138,7 +1134,11 @@ function initWithStyle({style, codeIsUpdated}) {
|
||||||
function add() {
|
function add() {
|
||||||
var sectionDiv = addSection(null, queue.shift());
|
var sectionDiv = addSection(null, queue.shift());
|
||||||
maximizeCodeHeight(sectionDiv, !queue.length);
|
maximizeCodeHeight(sectionDiv, !queue.length);
|
||||||
updateLintReport(sectionDiv.CodeMirror, prefs.get("editor.lintDelay"));
|
const cm = sectionDiv.CodeMirror;
|
||||||
|
setTimeout(() => {
|
||||||
|
cm.setOption('lint', CodeMirror.defaults.lint);
|
||||||
|
updateLintReport(cm, 0);
|
||||||
|
}, prefs.get("editor.lintDelay"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user