From 00687983f0a6f277f2bcb2f60ea35575aaa3f734 Mon Sep 17 00:00:00 2001 From: eight Date: Wed, 10 Oct 2018 18:21:07 +0800 Subject: [PATCH] Fix: default value --- edit/codemirror-default.js | 5 ----- edit/codemirror-factory.js | 15 +++++++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/edit/codemirror-default.js b/edit/codemirror-default.js index d3a612a4..aa6e2f14 100644 --- a/edit/codemirror-default.js +++ b/edit/codemirror-default.js @@ -9,7 +9,6 @@ } const defaults = { - autocompleteOnTyping: prefs.get('editor.autocompleteOnTyping'), extraKeys: Object.assign(CodeMirror.defaults.extraKeys || {}, { // independent of current keyMap 'Alt-Enter': 'toggleStyle', @@ -25,18 +24,14 @@ ], // 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'), }; diff --git a/edit/codemirror-factory.js b/edit/codemirror-factory.js index a70f351a..a19979b7 100644 --- a/edit/codemirror-factory.js +++ b/edit/codemirror-factory.js @@ -11,23 +11,25 @@ const cmFactory = (() => { const INSERT_TAB_COMMAND = CodeMirror.commands.insertTab; 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)); }); - CodeMirror.defineOption('indentWithTabs', (cm, value) => { + CodeMirror.defineOption('indentWithTabs', prefs.get('editor.indentWithTabs'), (cm, value) => { CodeMirror.commands.insertTab = value ? INSERT_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'; cm[onOff]('changes', autocompleteOnTyping); cm[onOff]('pick', autocompletePicked); }); - CodeMirror.defineOption('matchHighlight', (cm, value) => { + CodeMirror.defineOption('matchHighlight', prefs.get('editor.matchHighlight'), (cm, value) => { if (value === 'token') { cm.setOption('highlightSelectionMatches', { 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); }); @@ -59,7 +61,8 @@ const cmFactory = (() => { } // FIXME: is this an overhead? 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') { const themeLink = $('#cm-theme');