Browse Source

fix: remove empty paint frame when opening editor

tophf 3 years ago
parent
commit
b472b22d34
2 changed files with 13 additions and 16 deletions
  1. 3 10
      src/options/views/edit/index.vue
  2. 10 6
      src/options/views/tab-installed.vue

+ 3 - 10
src/options/views/edit/index.vue

@@ -70,7 +70,7 @@ import { keyboardService } from '@/common/keyboard';
 import VmCode from '@/common/ui/code';
 import VmExternals from '@/common/ui/externals';
 import options from '@/common/options';
-import { route, getUnloadSentry } from '@/common/router';
+import { getUnloadSentry } from '@/common/router';
 import { store } from '../../utils';
 import VmSettings from './settings';
 import VmValues from './values';
@@ -144,7 +144,7 @@ const K_NEXT_PANEL = 'Alt-PageDown';
 const compareString = (a, b) => (a < b ? -1 : a > b);
 
 export default {
-  props: ['initial'],
+  props: ['initial', 'initialCode'],
   components: {
     VmCode,
     VmSettings,
@@ -220,14 +220,6 @@ export default {
   async mounted() {
     store.storageSize = 0;
     this.nav = 'code';
-    const id = this.script?.props?.id;
-    if (id) {
-      this.code = await sendCmdDirectly('GetScriptCode', id);
-    } else {
-      const { script, code } = await sendCmdDirectly('NewScript', route.paths[2]);
-      this.script = script;
-      this.code = code;
-    }
     const { custom, config } = this.script;
     const { noframes } = custom;
     this.settings = {
@@ -272,6 +264,7 @@ export default {
         condition: '!tabCode',
       }),
     ];
+    this.code = this.initialCode;
   },
   methods: {
     async save() {

+ 10 - 6
src/options/views/tab-installed.vue

@@ -134,7 +134,7 @@
         />
       </div>
     </div>
-    <edit v-if="script" :initial="script" @close="editScript()"></edit>
+    <edit v-if="script" :initial="script" :initial-code="code" @close="editScript()" />
   </div>
 </template>
 
@@ -263,6 +263,7 @@ export default {
       filteredScripts: [],
       focusedIndex: -1,
       script: null,
+      code: '',
       search: null,
       searchError: null,
       modal: null,
@@ -405,14 +406,16 @@ export default {
         setRoute(pathname);
       }
     },
-    onHashChange() {
-      const [tab, id] = this.store.route.paths;
+    async onHashChange() {
+      const [tab, id, cacheId] = this.store.route.paths;
       if (id === '_new') {
-        sendCmdDirectly('NewScript').then(res => { this.script = res.script; });
+        Object.assign(this, await sendCmdDirectly('NewScript', cacheId));
       } else {
         const nid = id && +id || null;
-        this.script = nid && this.scripts.find(script => script.props.id === nid);
-        if (!this.script) {
+        const script = nid && this.scripts.find(s => s.props.id === nid);
+        if (script) {
+          this.code = await sendCmdDirectly('GetScriptCode', id);
+        } else {
           // First time showing the list we need to tell v-if to keep it forever
           if (!this.canRenderScripts) {
             loadData();
@@ -423,6 +426,7 @@ export default {
           // which was hidden to avoid flicker on initial page load directly into the editor.
           if (id) setRoute(tab, true);
         }
+        this.script = script;
       }
     },
     async renderScripts() {