Skip to content

Commit 2ba1eca

Browse files
committed
fix(app): load tab on open file
1 parent e3b6d84 commit 2ba1eca

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

packages/app/src/pages/session.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ export default function Page() {
720720
showAllFiles,
721721
tabForPath: file.tab,
722722
openTab: tabs().open,
723+
setActive: tabs().setActive,
723724
loadFile: file.load,
724725
})
725726

packages/app/src/pages/session/helpers.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ describe("createOpenReviewFile", () => {
1111
return `file://${path}`
1212
},
1313
openTab: (tab) => calls.push(`open:${tab}`),
14+
setActive: (tab) => calls.push(`active:${tab}`),
1415
loadFile: (path) => calls.push(`load:${path}`),
1516
})
1617

1718
openReviewFile("src/a.ts")
1819

19-
expect(calls).toEqual(["show", "load:src/a.ts", "tab:src/a.ts", "open:file://src/a.ts"])
20+
expect(calls).toEqual(["show", "load:src/a.ts", "tab:src/a.ts", "open:file://src/a.ts", "active:file://src/a.ts"])
2021
})
2122
})
2223

packages/app/src/pages/session/helpers.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,20 @@ export const createOpenReviewFile = (input: {
2424
showAllFiles: () => void
2525
tabForPath: (path: string) => string
2626
openTab: (tab: string) => void
27+
setActive: (tab: string) => void
2728
loadFile: (path: string) => any | Promise<void>
2829
}) => {
2930
return (path: string) => {
3031
batch(() => {
3132
input.showAllFiles()
3233
const maybePromise = input.loadFile(path)
33-
const openTab = () => input.openTab(input.tabForPath(path))
34-
if (maybePromise instanceof Promise) maybePromise.then(openTab)
35-
else openTab()
34+
const open = () => {
35+
const tab = input.tabForPath(path)
36+
input.openTab(tab)
37+
input.setActive(tab)
38+
}
39+
if (maybePromise instanceof Promise) maybePromise.then(open)
40+
else open()
3641
})
3742
}
3843
}

0 commit comments

Comments
 (0)