|
|
|
@ -17,10 +17,11 @@ import * as monaco from 'monaco-editor'
|
|
|
|
|
|
|
|
|
|
import { fromStore, toStore } from 'educoder'
|
|
|
|
|
import './TPIMonacoConfig'
|
|
|
|
|
import { isThisSecond } from 'date-fns';
|
|
|
|
|
|
|
|
|
|
// https://microsoft.github.io/monaco-editor/playground.html#customizing-the-appearence-exposed-colors
|
|
|
|
|
monaco.editor.defineTheme('myCoolTheme', {
|
|
|
|
|
base: 'vs-dark',
|
|
|
|
|
base: 'vs', // vs、vs-dark、hc-black
|
|
|
|
|
inherit: true,
|
|
|
|
|
rules: [
|
|
|
|
|
{ token: 'green', background: 'FF0000', foreground: '00FF00', fontStyle: 'italic'},
|
|
|
|
@ -213,11 +214,13 @@ class TPIMonaco extends Component {
|
|
|
|
|
loadMonacoResouce();
|
|
|
|
|
this.state = {
|
|
|
|
|
cmFontSize: fromStore('cmFontSize', 16),
|
|
|
|
|
cmCodeMode: fromStore('cmCodeMode', 'vs-dark'),
|
|
|
|
|
autoCompleteSwitch: fromStore('autoCompleteSwitch', true),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps, prevState, snapshot) {
|
|
|
|
|
console.log('++++++++++++++', prevState, this.state);
|
|
|
|
|
const { mirror_name } = this.props
|
|
|
|
|
const editor_monaco = this.editor_monaco;
|
|
|
|
|
if (editor_monaco && !_.isEqual(prevProps.mirror_name, mirror_name)) {
|
|
|
|
@ -243,7 +246,6 @@ class TPIMonaco extends Component {
|
|
|
|
|
editor_monaco.setValue(this.props.repositoryCode)
|
|
|
|
|
}
|
|
|
|
|
// 代码没变也需要layout,可能从命令行自动切回了代码tab
|
|
|
|
|
editor_monaco.layout();
|
|
|
|
|
|
|
|
|
|
// Clears the editor's undo history.
|
|
|
|
|
// TODO
|
|
|
|
@ -290,11 +292,12 @@ class TPIMonaco extends Component {
|
|
|
|
|
language: lang,
|
|
|
|
|
// language: 'css',
|
|
|
|
|
|
|
|
|
|
// theme: "vs-dark",
|
|
|
|
|
theme: "myCoolTheme",
|
|
|
|
|
// theme: "vs",
|
|
|
|
|
theme: this.state.cmCodeMode,
|
|
|
|
|
// theme: 'myCoolTheme',
|
|
|
|
|
insertSpaces: false,
|
|
|
|
|
fontSize: this.state.cmFontSize
|
|
|
|
|
|
|
|
|
|
fontSize: this.state.cmFontSize,
|
|
|
|
|
// theme: this.state.cdCodeMode
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window.editor_monaco = editor;
|
|
|
|
@ -368,10 +371,17 @@ class TPIMonaco extends Component {
|
|
|
|
|
}
|
|
|
|
|
onFontSizeChange = (value) => {
|
|
|
|
|
toStore('cmFontSize', value)
|
|
|
|
|
this.setState({ cmFontSize: value });
|
|
|
|
|
this.editor_monaco.updateOptions({fontSize: value})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setState({ cmFontSize: value });
|
|
|
|
|
onCodeModeChange = (value) => {
|
|
|
|
|
toStore('cmCodeMode', value);
|
|
|
|
|
this.setState({ cmCodeMode: value });
|
|
|
|
|
window.monaco.editor.setTheme(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onAutoCompleteSwitchChange = () => {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -393,6 +403,7 @@ class TPIMonaco extends Component {
|
|
|
|
|
>
|
|
|
|
|
<TPICodeSetting {...this.props} {...this.state}
|
|
|
|
|
onFontSizeChange={this.onFontSizeChange}
|
|
|
|
|
onCodeModeChange={this.onCodeModeChange}
|
|
|
|
|
onAutoCompleteSwitchChange={this.onAutoCompleteSwitchChange}
|
|
|
|
|
></TPICodeSetting>
|
|
|
|
|
</Drawer>
|
|
|
|
|