Fix: default options

This commit is contained in:
eight 2018-10-10 18:02:51 +08:00
parent c23f315c52
commit ff6fd8cad3
3 changed files with 29 additions and 25 deletions

View File

@ -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'));

View File

@ -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);
}
}

View File

@ -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)
));
};
})();