Fix: default value

This commit is contained in:
eight 2018-10-10 18:21:07 +08:00
parent ff6fd8cad3
commit 00687983f0
2 changed files with 9 additions and 11 deletions

View File

@ -9,7 +9,6 @@
} }
const defaults = { const defaults = {
autocompleteOnTyping: prefs.get('editor.autocompleteOnTyping'),
extraKeys: Object.assign(CodeMirror.defaults.extraKeys || {}, { extraKeys: Object.assign(CodeMirror.defaults.extraKeys || {}, {
// independent of current keyMap // independent of current keyMap
'Alt-Enter': 'toggleStyle', 'Alt-Enter': 'toggleStyle',
@ -25,18 +24,14 @@
], ],
// highlightSelectionMatches: {showToken: /[#.\-\w]/, annotateScrollbar: true}, // highlightSelectionMatches: {showToken: /[#.\-\w]/, annotateScrollbar: true},
hintOptions: {}, hintOptions: {},
indentWithTabs: prefs.get('editor.indentWithTabs'),
keyMap: prefs.get('editor.keyMap'), keyMap: prefs.get('editor.keyMap'),
lintReportDelay: prefs.get('editor.lintReportDelay'), lintReportDelay: prefs.get('editor.lintReportDelay'),
lineNumbers: true, lineNumbers: true,
lineWrapping: prefs.get('editor.lineWrapping'), lineWrapping: prefs.get('editor.lineWrapping'),
matchBrackets: true, matchBrackets: true,
matchHighlight: prefs.get('editor.matchHighlight'),
maxHighlightLength: 100e3, maxHighlightLength: 100e3,
mode: 'css', mode: 'css',
styleActiveLine: true, styleActiveLine: true,
selectByTokens: prefs.get('editor.selectByTokens'),
tabSize: prefs.get('editor.tabSize'),
theme: prefs.get('editor.theme'), theme: prefs.get('editor.theme'),
}; };

View File

@ -11,23 +11,25 @@ const cmFactory = (() => {
const INSERT_TAB_COMMAND = CodeMirror.commands.insertTab; const INSERT_TAB_COMMAND = CodeMirror.commands.insertTab;
const INSERT_SOFT_TAB_COMMAND = CodeMirror.commands.insertSoftTab; const INSERT_SOFT_TAB_COMMAND = CodeMirror.commands.insertSoftTab;
CodeMirror.defineOption('tabSize', (cm, value) => { console.log(INSERT_SOFT_TAB_COMMAND, INSERT_TAB_COMMAND);
CodeMirror.defineOption('tabSize', prefs.get('editor.tabSize'), (cm, value) => {
cm.setOption('indentUnit', Number(value)); cm.setOption('indentUnit', Number(value));
}); });
CodeMirror.defineOption('indentWithTabs', (cm, value) => { CodeMirror.defineOption('indentWithTabs', prefs.get('editor.indentWithTabs'), (cm, value) => {
CodeMirror.commands.insertTab = value ? CodeMirror.commands.insertTab = value ?
INSERT_TAB_COMMAND : INSERT_TAB_COMMAND :
INSERT_SOFT_TAB_COMMAND; INSERT_SOFT_TAB_COMMAND;
}); });
CodeMirror.defineOption('autocompleteOnTyping', (cm, value) => { CodeMirror.defineOption('autocompleteOnTyping', prefs.get('editor.autocompleteOnTyping'), (cm, value) => {
const onOff = value ? 'on' : 'off'; const onOff = value ? 'on' : 'off';
cm[onOff]('changes', autocompleteOnTyping); cm[onOff]('changes', autocompleteOnTyping);
cm[onOff]('pick', autocompletePicked); cm[onOff]('pick', autocompletePicked);
}); });
CodeMirror.defineOption('matchHighlight', (cm, value) => { CodeMirror.defineOption('matchHighlight', prefs.get('editor.matchHighlight'), (cm, value) => {
if (value === 'token') { if (value === 'token') {
cm.setOption('highlightSelectionMatches', { cm.setOption('highlightSelectionMatches', {
showToken: /[#.\-\w]/, showToken: /[#.\-\w]/,
@ -43,7 +45,7 @@ const cmFactory = (() => {
} }
}); });
CodeMirror.defineOption('selectByTokens', (cm, value) => { CodeMirror.defineOption('selectByTokens', prefs.get('editor.selectByTokens'), (cm, value) => {
cm.setOption('configureMouse', value ? configureMouseFn : null); cm.setOption('configureMouse', value ? configureMouseFn : null);
}); });
@ -59,7 +61,8 @@ const cmFactory = (() => {
} }
// FIXME: is this an overhead? // FIXME: is this an overhead?
if (option === 'autoCloseBrackets' && value) { if (option === 'autoCloseBrackets' && value) {
loadScript('/vendor/codemirror/addon/edit/closebrackets.js'); return loadScript('/vendor/codemirror/addon/edit/closebrackets.js')
.then(() => setOption(option, value));
} }
if (option === 'theme') { if (option === 'theme') {
const themeLink = $('#cm-theme'); const themeLink = $('#cm-theme');