From 1ced61a5cd0ed5c6a4501f480c8febd3b6249a3c Mon Sep 17 00:00:00 2001 From: Stanislav Romanov Date: Mon, 17 Oct 2022 11:46:00 +0300 Subject: [PATCH] Refactore initialization of monac editor --- app/components/monaco-editor.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/app/components/monaco-editor.js b/app/components/monaco-editor.js index 2b83b9d..b5b5fe3 100644 --- a/app/components/monaco-editor.js +++ b/app/components/monaco-editor.js @@ -48,17 +48,10 @@ export default class MonacoEditorComponent extends Component { @action initEditor(el) { - const model = getModel( - this.args.value, - this.args.language, - this.args.uri, - this.args.schema - ); - - this.editor = editor.create(el, { - model, + const options = { // theme: 'vs-dark', //TODO: add checking global theme readOnly: this.args.readOnly ?? false, + language: this.args.language, // wordWrap: 'on', // wrappingIndent: 'same', lineNumbers: 'off', @@ -67,7 +60,20 @@ export default class MonacoEditorComponent extends Component { minimap: { enabled: false, }, - }); + }; + + if (this.args.uri) { + options.model = getModel( + this.args.value, + this.args.language, + this.args.uri, + this.args.schema + ); + } else if (this.args.value) { + options.value = this.args.value; + } + + this.editor = editor.create(el, options); // Autoresize height of element const onDidContentSizeChangeHandler = this.editor.onDidContentSizeChange(