This commit is contained in:
Simon Genin (ges)
2020-10-14 20:33:00 +02:00
parent 35121dff59
commit 6aaa174a8a
+69 -14
View File
@@ -206,9 +206,14 @@ class Editor extends owl.Component {
currentExtension: 'js', currentExtension: 'js',
js: this.props.js, js: this.props.js,
css: this.props.css, css: this.props.css,
xml: this.props.xml xml: this.props.xml,
}) })
jsModel = null;
cssModel = null;
xmlModel = null;
editor = null; editor = null;
willUpdateProps(nextProps) { willUpdateProps(nextProps) {
@@ -216,6 +221,11 @@ class Editor extends owl.Component {
this.state.js = nextProps.js; this.state.js = nextProps.js;
this.state.css = nextProps.css; this.state.css = nextProps.css;
this.state.xml = nextProps.xml; this.state.xml = nextProps.xml;
this.jsModel = null;
this.cssModel = null;
this.xmlModel = null;
this._openFile(this.state.currentExtension, false) this._openFile(this.state.currentExtension, false)
} }
@@ -230,24 +240,69 @@ class Editor extends owl.Component {
_openFile(extension, save = true) { _openFile(extension, save = true) {
if (save) this._saveCodeState(); if (save) this._saveCodeState();
this.state.currentExtension = extension; this.state.currentExtension = extension;
let language = 'javascript'; let language = null;
switch (extension) { let model = null;
case 'xml':
language = 'xml'; if (extension === 'js') {
break; console.log("here")
case 'css':
language = 'css'; if (this.jsModel) {
break; model = this.jsModel;
}
else {
language = 'javascript'
}
} }
const model = monaco.editor.createModel( if (extension === 'xml') {
this.state[this.state.currentExtension],
language, if (this.xmlModel) {
null model = this.xmlModel;
) }
else {
language = 'xml'
}
}
if (extension === 'css') {
if (this.cssModel) {
model = this.cssModel;
}
else {
language = 'css'
}
}
console.log(model)
if (!model) {
model = monaco.editor.createModel(
this.state[this.state.currentExtension],
language,
null
)
if (extension === 'js') {
this.jsModel = model;
}
if (extension === 'xml') {
this.xmlModel = model;
}
if (extension === 'css') {
this.cssModel = model;
}
}
this.editor.setModel(model) this.editor.setModel(model)
} }
mounted() { mounted() {