diff --git a/edit.html b/edit.html index c5462681..34b695de 100644 --- a/edit.html +++ b/edit.html @@ -57,8 +57,6 @@ - - diff --git a/edit/codemirror-default.js b/edit/codemirror-default.js index e642ca3e..a46dba00 100644 --- a/edit/codemirror-default.js +++ b/edit/codemirror-default.js @@ -1,4 +1,4 @@ -/* global CodeMirror prefs */ +/* global CodeMirror prefs loadScript */ 'use strict'; @@ -100,16 +100,16 @@ }); } - CodeMirror.modeURL = '/vendor/codemirror/mode/%N/%N.js'; - const MODE = { stylus: 'stylus', uso: 'css' }; CodeMirror.defineExtension('setPreprocessor', function (preprocessor) { - this.setOption('mode', MODE[preprocessor] || 'css'); - CodeMirror.autoLoadMode(this, MODE[preprocessor] || 'css'); + const mode = MODE[preprocessor] || 'css'; + return loadScript(mode !== 'css' && `/vendor/codemirror/mode/${mode}/${mode}.js`).then(() => { + this.setOption('mode', mode); + }); }); CodeMirror.defineExtension('isBlank', function () { diff --git a/edit/source-editor.js b/edit/source-editor.js index 7ad3d326..5cdd60d2 100644 --- a/edit/source-editor.js +++ b/edit/source-editor.js @@ -44,22 +44,23 @@ function createSourceEditor(style) { const cm = CodeMirror.fromTextArea($('#sections textarea')); cm.startOperation(); - cm.setValue(style.sourceCode); - cm.clearHistory(); - cm.markClean(); - editors.push(cm); - updateMeta(); - cm.endOperation(); + updateMeta().then(() => { + cm.setValue(style.sourceCode); + cm.clearHistory(); + cm.markClean(); + editors.push(cm); + cm.endOperation(); - initHooks(); - initAppliesToLineWidget(); + initHooks(); + initAppliesToLineWidget(); + + // focus must be the last action, otherwise the style is duplicated on saving + cm.focus(); + }); initLint(); initLinterSwitch(); - // focus must be the last action, otherwise the style is duplicated on saving - cm.focus(); - function initAppliesToLineWidget() { const PREF_NAME = 'editor.appliesToLineWidget'; const widget = createAppliesToLineWidget(cm); @@ -183,10 +184,10 @@ ${section} $('#enabled').checked = style.enabled; $('#url').href = style.url; const {usercssData: {preprocessor} = {}} = style; - cm.setPreprocessor(preprocessor); // beautify only works with regular CSS $('#beautify').disabled = cm.getOption('mode') !== 'css'; updateTitle(); + return cm.setPreprocessor(preprocessor); } function updateTitle() { diff --git a/install-usercss.html b/install-usercss.html index ca301b1d..b8b473d7 100644 --- a/install-usercss.html +++ b/install-usercss.html @@ -12,6 +12,7 @@ + @@ -47,7 +48,6 @@ -