fix:modifying js code themes (#230)
* fix:modifying js code themes * define themes only once
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
0c7c8e26bf
commit
da7c1ebafd
@ -39,6 +39,34 @@ const modeMap = {
|
|||||||
jsx: 'javascript'
|
jsx: 'javascript'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var monacoThemesDefined = false;
|
||||||
|
const defineMonacoThemes = (monaco) => {
|
||||||
|
if (monacoThemesDefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
monacoThemesDefined = true;
|
||||||
|
const yellowCollor = 'FFFF00';
|
||||||
|
const lightBlueColor = '9CDCFE';
|
||||||
|
const darkBlueColor = '00107E';
|
||||||
|
monaco.editor.defineTheme('vs-dark-custom', {
|
||||||
|
base: 'vs-dark',
|
||||||
|
inherit: true,
|
||||||
|
rules: [
|
||||||
|
{ token: 'delimiter.js', foreground: lightBlueColor },
|
||||||
|
{ token: 'delimiter.parenthesis.js', foreground: yellowCollor },
|
||||||
|
{ token: 'delimiter.array.js', foreground: yellowCollor },
|
||||||
|
{ token: 'delimiter.bracket.js', foreground: yellowCollor }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
monaco.editor.defineTheme('vs-custom', {
|
||||||
|
base: 'vs',
|
||||||
|
inherit: true,
|
||||||
|
rules: [
|
||||||
|
{ token: 'identifier.js', foreground: darkBlueColor }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
class Editor extends PureComponent {
|
class Editor extends PureComponent {
|
||||||
constructor(...props) {
|
constructor(...props) {
|
||||||
super(...props);
|
super(...props);
|
||||||
@ -65,6 +93,10 @@ class Editor extends PureComponent {
|
|||||||
document.removeEventListener('keyup', this.focusEditor);
|
document.removeEventListener('keyup', this.focusEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
editorWillMount(monaco) {
|
||||||
|
defineMonacoThemes(monaco);
|
||||||
|
}
|
||||||
|
|
||||||
editorDidMount(editor, monaco) {
|
editorDidMount(editor, monaco) {
|
||||||
this._editor = editor;
|
this._editor = editor;
|
||||||
this._editor.focus();
|
this._editor.focus();
|
||||||
@ -100,12 +132,13 @@ class Editor extends PureComponent {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { contents, ext, theme, fileKey } = this.props;
|
const { contents, ext, theme, fileKey } = this.props;
|
||||||
const editorTheme = theme === 'night' ? 'vs-dark' : 'vs';
|
const editorTheme = theme === 'night' ? 'vs-dark-custom' : 'vs-custom';
|
||||||
return (
|
return (
|
||||||
<div className='classic-editor editor'>
|
<div className='classic-editor editor'>
|
||||||
<base href='/' />
|
<base href='/' />
|
||||||
<MonacoEditor
|
<MonacoEditor
|
||||||
editorDidMount={::this.editorDidMount}
|
editorDidMount={::this.editorDidMount}
|
||||||
|
editorWillMount={::this.editorWillMount}
|
||||||
key={`${editorTheme}-${fileKey}`}
|
key={`${editorTheme}-${fileKey}`}
|
||||||
language={modeMap[ext]}
|
language={modeMap[ext]}
|
||||||
onChange={::this.onChange}
|
onChange={::this.onChange}
|
||||||
|
Reference in New Issue
Block a user