420733b93a
* add Patch CSP option * show style version, size, and update age in manager * add scope selector to style search in manager * keep scroll position and selections in tab's session * directly install usercss from raw github links * ditch localStorage, use on-demand SessionStore proxy * simplify localization * allow <code> tag in i18n-html * keep nodes in HTML templates * API.getAllStyles is actually faster with code untouched * fix fitToContent when applies-to is taller than window * dedupe linter.enableForEditor calls * prioritize visible CMs in refreshOnViewListener * don't scroll to last style on editing a new one * delay colorview for invisible CMs * eslint comma-dangle error + autofix files * styleViaXhr: also toggle for disableAll pref * styleViaXhr: allow cookies for sandbox CSP * simplify notes in options * simplify getStylesViaXhr * oldUI fixups: * remove separator before 1st applies-to * center name bubbles * fix updateToc focus on a newly added section * fix fitToContent when cloning section * remove CSS `contain` as it makes no difference * replace overrides with declarative CSS + code cosmetics * simplify adjustWidth and make it work in FF
67 lines
1.2 KiB
JavaScript
67 lines
1.2 KiB
JavaScript
/* global workerUtil */
|
|
'use strict';
|
|
|
|
/* exported editorWorker */
|
|
const editorWorker = workerUtil.createWorker({
|
|
url: '/edit/editor-worker.js',
|
|
});
|
|
|
|
/* exported linter */
|
|
const linter = (() => {
|
|
const lintingUpdatedListeners = [];
|
|
const unhookListeners = [];
|
|
const linters = [];
|
|
const cms = new Set();
|
|
|
|
return {
|
|
register,
|
|
run,
|
|
enableForEditor,
|
|
disableForEditor,
|
|
onLintingUpdated,
|
|
onUnhook,
|
|
};
|
|
|
|
function onUnhook(cb) {
|
|
unhookListeners.push(cb);
|
|
}
|
|
|
|
function onLintingUpdated(cb) {
|
|
lintingUpdatedListeners.push(cb);
|
|
}
|
|
|
|
function onUpdateLinting(...args) {
|
|
for (const cb of lintingUpdatedListeners) {
|
|
cb(...args);
|
|
}
|
|
}
|
|
|
|
function enableForEditor(cm) {
|
|
cm.setOption('lint', {onUpdateLinting, getAnnotations});
|
|
cms.add(cm);
|
|
}
|
|
|
|
function disableForEditor(cm) {
|
|
cm.setOption('lint', false);
|
|
cms.delete(cm);
|
|
for (const cb of unhookListeners) {
|
|
cb(cm);
|
|
}
|
|
}
|
|
|
|
function register(linterFn) {
|
|
linters.push(linterFn);
|
|
}
|
|
|
|
function run() {
|
|
for (const cm of cms) {
|
|
cm.performLint();
|
|
}
|
|
}
|
|
|
|
function getAnnotations(...args) {
|
|
return Promise.all(linters.map(fn => fn(...args)))
|
|
.then(results => [].concat(...results.filter(Boolean)));
|
|
}
|
|
})();
|