Switch to new linter/worker
This commit is contained in:
parent
054d94ebd2
commit
ca5c0e92cd
27
edit/edit.js
27
edit/edit.js
|
@ -6,7 +6,7 @@ global setupCodeMirror
|
|||
global beautify
|
||||
global initWithSectionStyle addSections removeSection getSectionsHashes
|
||||
global sectionsToMozFormat
|
||||
global moveFocus
|
||||
global moveFocus editorWorker
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
|
@ -211,7 +211,6 @@ function beforeUnload() {
|
|||
}
|
||||
const isDirty = editor ? editor.isDirty() : !isCleanGlobal();
|
||||
if (isDirty) {
|
||||
updateLintReportIfEnabled(null, 0);
|
||||
// neither confirm() nor custom messages work in modern browsers but just in case
|
||||
return t('styleChangesNotSaved');
|
||||
}
|
||||
|
@ -275,9 +274,6 @@ function initHooks() {
|
|||
$('#save-button').addEventListener('click', save, false);
|
||||
$('#sections-help').addEventListener('click', showSectionHelp, false);
|
||||
|
||||
// TODO: investigate why FF needs this delay
|
||||
debounce(initLint, FIREFOX ? 100 : 0);
|
||||
|
||||
if (!FIREFOX) {
|
||||
$$([
|
||||
'input:not([type])',
|
||||
|
@ -352,7 +348,6 @@ function toggleStyle() {
|
|||
}
|
||||
|
||||
function save() {
|
||||
updateLintReportIfEnabled(null, 0);
|
||||
if (!validate()) {
|
||||
return;
|
||||
}
|
||||
|
@ -413,12 +408,6 @@ function updateTitle() {
|
|||
$('#save-button').disabled = clean;
|
||||
}
|
||||
|
||||
function updateLintReportIfEnabled(...args) {
|
||||
if (CodeMirror.defaults.lint) {
|
||||
updateLintReport(...args);
|
||||
}
|
||||
}
|
||||
|
||||
function showMozillaFormat() {
|
||||
const popup = showCodeMirrorPopup(t('styleToMozillaFormatTitle'), '', {readOnly: true});
|
||||
popup.codebox.setValue(toMozillaFormat());
|
||||
|
@ -460,16 +449,7 @@ function fromMozillaFormat() {
|
|||
|
||||
function doImport({replaceOldStyle = false}) {
|
||||
lockPageUI(true);
|
||||
new Promise(setTimeout)
|
||||
.then(() => {
|
||||
const worker = linterConfig.worker.csslint;
|
||||
if (!worker.instance) worker.instance = new Worker(worker.path);
|
||||
})
|
||||
.then(() => linterConfig.invokeWorker({
|
||||
linter: 'csslint',
|
||||
action: 'parse',
|
||||
code: popup.codebox.getValue().trim(),
|
||||
}))
|
||||
editorWorker.parseMozFormat(popup.codebox.getValue().trim())
|
||||
.then(({sections, errors}) => {
|
||||
// shouldn't happen but just in case
|
||||
if (!sections.length && errors.length) {
|
||||
|
@ -482,8 +462,7 @@ function fromMozillaFormat() {
|
|||
removeOldSections(replaceOldStyle);
|
||||
return addSections(sections, div => setCleanItem(div, false));
|
||||
})
|
||||
.then(sectionDivs => {
|
||||
sectionDivs.forEach(div => updateLintReportIfEnabled(div.CodeMirror, 1));
|
||||
.then(() => {
|
||||
$('.dismiss').dispatchEvent(new Event('click'));
|
||||
})
|
||||
.catch(showError)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
global CodeMirror
|
||||
global editors propertyToCss CssToProperty
|
||||
global onChange indicateCodeChange initHooks setCleanGlobal
|
||||
global onChange initHooks setCleanGlobal
|
||||
global fromMozillaFormat maximizeCodeHeight toggleContextMenuDelete
|
||||
global setCleanItem updateTitle
|
||||
global showAppliesToHelp beautify regExpTester setGlobalProgress setCleanSection
|
||||
global clipString
|
||||
global clipString linter linterReport
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
|
@ -146,12 +146,13 @@ function addSection(event, section) {
|
|||
const newIndex = getSections().indexOf(clickedSection) + 1;
|
||||
cm = setupCodeMirror(div, code, newIndex);
|
||||
makeSectionVisible(cm);
|
||||
renderLintReport();
|
||||
cm.focus();
|
||||
} else {
|
||||
sections.appendChild(div);
|
||||
cm = setupCodeMirror(div, code);
|
||||
}
|
||||
linter.hook(cm);
|
||||
linterReport.refresh();
|
||||
div.CodeMirror = cm;
|
||||
setCleanSection(div);
|
||||
return div;
|
||||
|
@ -308,7 +309,6 @@ function indicateCodeChange(cm) {
|
|||
const section = cm.getSection();
|
||||
setCleanItem(section, cm.isClean(section.savedValue));
|
||||
updateTitle();
|
||||
updateLintReportIfEnabled(cm);
|
||||
}
|
||||
|
||||
function setupAutocomplete(cm, enable = true) {
|
||||
|
@ -481,13 +481,16 @@ function removeSection(event) {
|
|||
setCleanItem(section, false);
|
||||
updateTitle();
|
||||
cm.focus();
|
||||
linter.hook(cm);
|
||||
linterReport.refresh();
|
||||
};
|
||||
section.insertAdjacentElement('afterend', stub);
|
||||
}
|
||||
setCleanItem($('#sections'), false);
|
||||
removeAreaAndSetDirty(section);
|
||||
editors.splice(editors.indexOf(cm), 1);
|
||||
renderLintReport();
|
||||
linter.unhook(cm);
|
||||
linterReport.refresh();
|
||||
}
|
||||
|
||||
function removeAreaAndSetDirty(area) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user