diff --git a/edit/codemirror-default.js b/edit/codemirror-default.js index 732e9a80..d3a612a4 100644 --- a/edit/codemirror-default.js +++ b/edit/codemirror-default.js @@ -10,22 +10,6 @@ const defaults = { autocompleteOnTyping: prefs.get('editor.autocompleteOnTyping'), - mode: 'css', - lineNumbers: true, - lineWrapping: prefs.get('editor.lineWrapping'), - foldGutter: true, - gutters: [ - 'CodeMirror-linenumbers', - 'CodeMirror-foldgutter', - ...(prefs.get('editor.linter') ? ['CodeMirror-lint-markers'] : []), - ], - matchBrackets: true, - highlightSelectionMatches: {showToken: /[#.\-\w]/, annotateScrollbar: true}, - hintOptions: {}, - lintReportDelay: prefs.get('editor.lintReportDelay'), - styleActiveLine: true, - theme: 'default', - keyMap: prefs.get('editor.keyMap'), extraKeys: Object.assign(CodeMirror.defaults.extraKeys || {}, { // independent of current keyMap 'Alt-Enter': 'toggleStyle', @@ -33,7 +17,27 @@ 'Alt-PageUp': 'prevEditor', 'Ctrl-Pause': 'toggleEditorFocus', }), + foldGutter: true, + gutters: [ + 'CodeMirror-linenumbers', + 'CodeMirror-foldgutter', + ...(prefs.get('editor.linter') ? ['CodeMirror-lint-markers'] : []), + ], + // highlightSelectionMatches: {showToken: /[#.\-\w]/, annotateScrollbar: true}, + hintOptions: {}, + indentWithTabs: prefs.get('editor.indentWithTabs'), + keyMap: prefs.get('editor.keyMap'), + lintReportDelay: prefs.get('editor.lintReportDelay'), + lineNumbers: true, + lineWrapping: prefs.get('editor.lineWrapping'), + matchBrackets: true, + matchHighlight: prefs.get('editor.matchHighlight'), maxHighlightLength: 100e3, + mode: 'css', + styleActiveLine: true, + selectByTokens: prefs.get('editor.selectByTokens'), + tabSize: prefs.get('editor.tabSize'), + theme: prefs.get('editor.theme'), }; Object.assign(CodeMirror.defaults, defaults, prefs.get('editor.options')); diff --git a/edit/codemirror-factory.js b/edit/codemirror-factory.js index 8c2346e8..a70f351a 100644 --- a/edit/codemirror-factory.js +++ b/edit/codemirror-factory.js @@ -70,14 +70,10 @@ const cmFactory = (() => { const url = chrome.runtime.getURL('vendor/codemirror/theme/' + value + '.css'); if (themeLink.href !== url) { // avoid flicker: wait for the second stylesheet to load, then apply the theme - return loadScript(url).then(([newThemeLink]) => { + return loadScript(url, true).then(([newThemeLink]) => { setOption(option, value); themeLink.remove(); newThemeLink.id = 'cm-theme'; - // already loaded but is removed. - if (!newThemeLink.parentNode) { - document.head.appendChild(newThemeLink); - } }); } } @@ -214,8 +210,8 @@ const cmFactory = (() => { throttleSetOption({key, value, index: 0}); return; } - for (const editor of editors) { - editor.setOption(key, value); + for (const cm of editors) { + cm.setOption(key, value); } } diff --git a/js/script-loader.js b/js/script-loader.js index a017ea02..f4c80bf6 100644 --- a/js/script-loader.js +++ b/js/script-loader.js @@ -37,11 +37,15 @@ var loadScript = (() => { }); } - return files => { + return (files, noCache = false) => { if (!Array.isArray(files)) { files = [files]; } - return Promise.all(files.map(f => (typeof f === 'string' ? inject(f) : f))); + return Promise.all(files.map(f => + typeof f !== 'string' ? f : + noCache ? doInject(f) : + inject(f) + )); }; })();