fix script body not loading in editor. Fix slow unload times for monaco editor

This commit is contained in:
sadnub
2023-10-29 10:24:16 -04:00
parent be37e89e16
commit 076ab0c465
2 changed files with 13 additions and 11 deletions

View File

@@ -4,9 +4,9 @@
persistent persistent
@keydown.esc.stop="onDialogHide" @keydown.esc.stop="onDialogHide"
:maximized="maximized" :maximized="maximized"
@keydown.esc="unloadEditor" @hide="onDialogHide"
@hide="unloadEditor"
@show="loadEditor" @show="loadEditor"
@before-hide="unloadEditor"
> >
<q-card <q-card
class="q-dialog-plugin" class="q-dialog-plugin"
@@ -329,12 +329,6 @@ const lang = computed(() => {
else return ""; else return "";
}); });
// get code if editing or cloning script
if (props.script)
downloadScript(script.id, { with_snippets: props.readonly }).then((r) => {
script.script_body = r.code;
});
async function submit() { async function submit() {
loading.value = true; loading.value = true;
let result = ""; let result = "";
@@ -391,6 +385,13 @@ function loadEditor() {
editor.onDidChangeModelContent(() => { editor.onDidChangeModelContent(() => {
script.script_body = editor.getValue(); script.script_body = editor.getValue();
}); });
// get code if editing or cloning script
if (props.script)
downloadScript(script.id, { with_snippets: props.readonly }).then((r) => {
script.script_body = r.code;
editor.setValue(r.code);
});
} }
function unloadEditor() { function unloadEditor() {

View File

@@ -2,10 +2,11 @@
<q-dialog <q-dialog
ref="dialogRef" ref="dialogRef"
persistent persistent
@keydown.esc="unloadEditor" @keydown.esc.stop="onDialogHide"
:maximized="maximized" :maximized="maximized"
@hide="unloadEditor" @hide="onDialogHide"
@show="loadEditor" @show="loadEditor"
@before-hide="unloadEditor"
> >
<q-card <q-card
class="q-dialog-plugin" class="q-dialog-plugin"
@@ -177,7 +178,7 @@ const snippetEditor = ref<HTMLElement | null>(null);
let editor: monaco.editor.IStandaloneCodeEditor; let editor: monaco.editor.IStandaloneCodeEditor;
function loadEditor() { function loadEditor() {
var modelUri = monaco.Uri.parse("model://new"); // a made up unique URI for our model var modelUri = monaco.Uri.parse("model://snippet"); // a made up unique URI for our model
var model = monaco.editor.createModel(snippet.code, lang.value, modelUri); var model = monaco.editor.createModel(snippet.code, lang.value, modelUri);
const theme = $q.dark.isActive ? "vs-dark" : "vs-light"; const theme = $q.dark.isActive ? "vs-dark" : "vs-light";