From 62ba1af749500f8075db7a724d3b563d91ef6c5d Mon Sep 17 00:00:00 2001 From: tangjiang <465264938@qq.com> Date: Fri, 29 Nov 2019 18:04:28 +0800 Subject: [PATCH] update editor config --- .../modules/page/component/TPICodeMirror.js | 16 ++++++++--- .../modules/page/component/TPICodeSetting.js | 25 +++++++++++++++-- .../page/component/monaco/TPIMonaco.css | 4 +-- .../page/component/monaco/TPIMonaco.js | 27 +++++++++++++------ 4 files changed, 57 insertions(+), 15 deletions(-) diff --git a/public/react/src/modules/page/component/TPICodeMirror.js b/public/react/src/modules/page/component/TPICodeMirror.js index 86f705478..9bfb714d4 100644 --- a/public/react/src/modules/page/component/TPICodeMirror.js +++ b/public/react/src/modules/page/component/TPICodeMirror.js @@ -33,13 +33,15 @@ function getModeByMirrorName(mirror_name) { return mode; } const _extraKeys = {"Alt-/": "autocomplete"}; -function createCMOptions(mirror_name) { +function createCMOptions(mirror_name, theme) { let mode = getModeByMirrorName(mirror_name) let cmOptions = { lineNumbers: true, mode: mode, - theme: "railscasts", + // theme: "railscasts", + // theme: "vs-dark", + theme: theme, indentUnit:4, matchBrackets: true, autoRefresh: true, @@ -97,6 +99,7 @@ class TPICodeMirror extends Component { super(props) this.state = { cmFontSize: fromStore('cmFontSize', 16), + cmCodeMode: fromStore('cmCodeMode', 'vs-dark'), autoCompleteSwitch: fromStore('autoCompleteSwitch', true), } } @@ -114,7 +117,7 @@ class TPICodeMirror extends Component { } } componentDidMount() { - let cmOptions = createCMOptions(this.props.mirror_name) + let cmOptions = createCMOptions(this.props.mirror_name, this.state.cmCodeMode) extend_editor = window.CodeMirror.fromTextArea(window.$('#extend-challenge-file-edit')[0] , cmOptions); @@ -241,6 +244,12 @@ class TPICodeMirror extends Component { this.setState({ cmFontSize: value }); } + onCodeModeChange = (value) => { + toStore('cmCodeMode', value); + this.setState({ cmCodeMode: value }); + window.monaco.editor.setTheme(value); + } + render() { const { repositoryCode, showSettingDrawer, settingDrawerOpen } = this.props; const { cmFontSize } = this.state; @@ -259,6 +268,7 @@ class TPICodeMirror extends Component { > diff --git a/public/react/src/modules/page/component/TPICodeSetting.js b/public/react/src/modules/page/component/TPICodeSetting.js index 51a9f390c..7f7e66698 100644 --- a/public/react/src/modules/page/component/TPICodeSetting.js +++ b/public/react/src/modules/page/component/TPICodeSetting.js @@ -18,12 +18,13 @@ class TPICodeSetting extends Component { render() { const { autoCompleteSwitch, onAutoCompleteSwitchChange, onFontSizeChange - , cmFontSize, + , cmFontSize, cmCodeMode, + onCodeModeChange, shixun } = this.props; const task_pass = shixun.task_pass const forbid_copy = shixun.forbid_copy const test_set_permission = shixun.test_set_permission - + console.log('==========', cmCodeMode); return (