fixup efc001c0: css_beautify is dodgy

This commit is contained in:
tophf 2017-08-29 14:28:13 +03:00
parent 73dc33d376
commit e65e3c9c0b
2 changed files with 19 additions and 5 deletions

View File

@ -1,6 +1,7 @@
/* eslint brace-style: 0, operator-linebreak: 0 */ /* eslint brace-style: 0, operator-linebreak: 0 */
/* global CodeMirror parserlib */ /* global CodeMirror parserlib */
/* global exports onDOMscripted */ /* global onDOMscripted */
/* global css_beautify */
/* global CSSLint initLint linterConfig updateLintReport renderLintReport updateLinter */ /* global CSSLint initLint linterConfig updateLintReport renderLintReport updateLinter */
'use strict'; 'use strict';
@ -1080,9 +1081,14 @@ function getEditorInSight(nearbyElement) {
} }
function beautify(event) { function beautify(event) {
const script = $('script[src*="beautify-css-mod"]') ? onDOMscripted([
[] : ['vendor-overwrites/beautify/beautify-css-mod.js']; 'vendor-overwrites/beautify/beautify-css-mod.js',
onDOMscripted(script).then(doBeautify); () => {
if (!window.css_beautify && window.exports) {
window.css_beautify = window.exports.css_beautify;
}
},
]).then(doBeautify);
function doBeautify() { function doBeautify() {
const tabs = prefs.get('editor.indentWithTabs'); const tabs = prefs.get('editor.indentWithTabs');
@ -1127,7 +1133,7 @@ function beautify(event) {
[].concat.apply([], cm.doc.sel.ranges.map(r => [].concat.apply([], cm.doc.sel.ranges.map(r =>
[Object.assign({}, r.anchor), Object.assign({}, r.head)])); [Object.assign({}, r.anchor), Object.assign({}, r.head)]));
const text = cm.getValue(); const text = cm.getValue();
const newText = exports.css_beautify(text, options); const newText = css_beautify(text, options);
if (newText !== text) { if (newText !== text) {
if (!cm.beautifyChange || !cm.beautifyChange[cm.changeGeneration()]) { if (!cm.beautifyChange || !cm.beautifyChange[cm.changeGeneration()]) {
// clear the list if last change wasn't a css-beautify // clear the list if last change wasn't a css-beautify

View File

@ -122,6 +122,14 @@ function injectScript(properties) {
if (!properties || !properties.src) { if (!properties || !properties.src) {
return; return;
} }
if (injectScript.cache) {
if (injectScript.cache.has(properties.src)) {
return Promise.resolve();
}
} else {
injectScript.cache = new Set();
}
injectScript.cache.add(properties.src);
const script = document.head.appendChild(document.createElement('script')); const script = document.head.appendChild(document.createElement('script'));
Object.assign(script, properties); Object.assign(script, properties);
if (!properties.onload) { if (!properties.onload) {