Преглед изворни кода

fix(app): load tab on open file

Adam пре 1 месец
родитељ
комит
2ba1ecabc9

+ 1 - 0
packages/app/src/pages/session.tsx

@@ -720,6 +720,7 @@ export default function Page() {
     showAllFiles,
     showAllFiles,
     tabForPath: file.tab,
     tabForPath: file.tab,
     openTab: tabs().open,
     openTab: tabs().open,
+    setActive: tabs().setActive,
     loadFile: file.load,
     loadFile: file.load,
   })
   })
 
 

+ 2 - 1
packages/app/src/pages/session/helpers.test.ts

@@ -11,12 +11,13 @@ describe("createOpenReviewFile", () => {
         return `file://${path}`
         return `file://${path}`
       },
       },
       openTab: (tab) => calls.push(`open:${tab}`),
       openTab: (tab) => calls.push(`open:${tab}`),
+      setActive: (tab) => calls.push(`active:${tab}`),
       loadFile: (path) => calls.push(`load:${path}`),
       loadFile: (path) => calls.push(`load:${path}`),
     })
     })
 
 
     openReviewFile("src/a.ts")
     openReviewFile("src/a.ts")
 
 
-    expect(calls).toEqual(["show", "load:src/a.ts", "tab:src/a.ts", "open:file://src/a.ts"])
+    expect(calls).toEqual(["show", "load:src/a.ts", "tab:src/a.ts", "open:file://src/a.ts", "active:file://src/a.ts"])
   })
   })
 })
 })
 
 

+ 8 - 3
packages/app/src/pages/session/helpers.ts

@@ -24,15 +24,20 @@ export const createOpenReviewFile = (input: {
   showAllFiles: () => void
   showAllFiles: () => void
   tabForPath: (path: string) => string
   tabForPath: (path: string) => string
   openTab: (tab: string) => void
   openTab: (tab: string) => void
+  setActive: (tab: string) => void
   loadFile: (path: string) => any | Promise<void>
   loadFile: (path: string) => any | Promise<void>
 }) => {
 }) => {
   return (path: string) => {
   return (path: string) => {
     batch(() => {
     batch(() => {
       input.showAllFiles()
       input.showAllFiles()
       const maybePromise = input.loadFile(path)
       const maybePromise = input.loadFile(path)
-      const openTab = () => input.openTab(input.tabForPath(path))
-      if (maybePromise instanceof Promise) maybePromise.then(openTab)
-      else openTab()
+      const open = () => {
+        const tab = input.tabForPath(path)
+        input.openTab(tab)
+        input.setActive(tab)
+      }
+      if (maybePromise instanceof Promise) maybePromise.then(open)
+      else open()
     })
     })
   }
   }
 }
 }