Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import CodeMirror from 'codemirror';
import { cmCmd } from '../is-mac';
// FIXME I want to *only* use the HTML formatter, and then use prettier
// for js, CSS and JSON - but I need something working now, so this is a start.
import * as tidy from 'js-beautify';
tidy.javascript = tidy.js; // alias to allow our named sources to work
CodeMirror.defineOption('autoFormat', false, (cm, autoFormatOn) => {
if (autoFormatOn) {
cm.on('keyHandled', (cm, name) => {
if (name === `${cmCmd}-S`) {
cm.autoFormat(cm);
}
});
}
});
CodeMirror.defineExtension('autoFormat', cm => {
let from, to;
const doc = cm.doc;
if (doc.somethingSelected()) {