Ver código fonte

store code snippet in mem

Martin Kunz 1 ano atrás
pai
commit
b3d0a8ac95
2 arquivos alterados com 21 adições e 6 exclusões
  1. 20 5
      src/components/TheEditor.vue
  2. 1 1
      src/components/TheParent.vue

+ 20 - 5
src/components/TheEditor.vue

@@ -1,7 +1,7 @@
 <script setup lang="ts">
 import { useStore, type IMappingValue } from '@/util/store'
 const store = useStore()
-import { ref, shallowRef } from 'vue'
+import { computed, shallowRef } from 'vue'
 
 //see https://github.com/imguolao/monaco-vue#vite
 import { loader } from "@guolao/vue-monaco-editor"
@@ -29,17 +29,32 @@ self.MonacoEnvironment = {
   }
 }
 loader.config({ monaco })
-
-
 const MONACO_EDITOR_OPTIONS = {
   automaticLayout: true,
   formatOnType: true,
   formatOnPaste: true,
 }
 
-const code = ref('')
+const node = computed(() => {
+    return store.selectedNode;
+});
+
+const code = computed(():string => {
+    if(!node.value)
+      return "";
+    if(!node.value.nodeId.value)
+      return "";
+    const m=store.mapping.get(node.value.nodeId.value.toString());
+    if(m)
+      return m.read;
+    return "";
+});
+
 const editorRef = shallowRef()
-const handleMount = (editor: any) => (editorRef.value = editor)
+const handleMount = (editor: any) => {
+  editorRef.value = editor
+
+}
 
 const onChange = (value: string | undefined, event: monaco.editor.IModelContentChangedEvent) => {
   if(!store.selectedNode)

+ 1 - 1
src/components/TheParent.vue

@@ -13,7 +13,7 @@ const node = computed(() => {
 
 <template>
   <div class="card">
-    <div class="card-body" v-if="store.selectedNode != null" :elem="store.selectedNode">
+    <div class="card-body" v-if="node != null">
       <h5 class="card-title">Parent</h5>
       <div class="card-text">
         <div class="input-group mb-3">