Jelajahi Sumber

chore: cleanup

Adam 6 bulan lalu
induk
melakukan
1133d87be0

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

@@ -1,5 +1,5 @@
 import { describe, expect, test } from "bun:test"
-import { createOpenReviewFile, focusTerminalById, getTabReorderIndex } from "./helpers"
+import { createOpenReviewFile, createOpenSessionFileTab, focusTerminalById, getTabReorderIndex } from "./helpers"
 
 describe("createOpenReviewFile", () => {
   test("opens and loads selected review file", () => {
@@ -20,6 +20,37 @@ describe("createOpenReviewFile", () => {
   })
 })
 
+describe("createOpenSessionFileTab", () => {
+  test("activates the opened file tab", () => {
+    const calls: string[] = []
+    const openTab = createOpenSessionFileTab({
+      normalizeTab: (value) => {
+        calls.push(`normalize:${value}`)
+        return `file://${value}`
+      },
+      openTab: (tab) => calls.push(`open:${tab}`),
+      pathFromTab: (tab) => {
+        calls.push(`path:${tab}`)
+        return tab.slice("file://".length)
+      },
+      loadFile: (path) => calls.push(`load:${path}`),
+      openReviewPanel: () => calls.push("review"),
+      setActive: (tab) => calls.push(`active:${tab}`),
+    })
+
+    openTab("src/a.ts")
+
+    expect(calls).toEqual([
+      "normalize:src/a.ts",
+      "open:file://src/a.ts",
+      "path:file://src/a.ts",
+      "load:src/a.ts",
+      "review",
+      "active:file://src/a.ts",
+    ])
+  })
+})
+
 describe("focusTerminalById", () => {
   test("focuses textarea when present", () => {
     document.body.innerHTML = `<div id="terminal-wrapper-one"><div data-component="terminal"><textarea></textarea></div></div>`

+ 21 - 0
packages/app/src/pages/session/helpers.ts

@@ -35,6 +35,27 @@ export const createOpenReviewFile = (input: {
   }
 }
 
+export const createOpenSessionFileTab = (input: {
+  normalizeTab: (tab: string) => string
+  openTab: (tab: string) => void
+  pathFromTab: (tab: string) => string | undefined
+  loadFile: (path: string) => void
+  openReviewPanel: () => void
+  setActive: (tab: string) => void
+}) => {
+  return (value: string) => {
+    const next = input.normalizeTab(value)
+    input.openTab(next)
+
+    const path = input.pathFromTab(next)
+    if (!path) return
+
+    input.loadFile(path)
+    input.openReviewPanel()
+    input.setActive(next)
+  }
+}
+
 export const getTabReorderIndex = (tabs: readonly string[], from: string, to: string) => {
   const fromIndex = tabs.indexOf(from)
   const toIndex = tabs.indexOf(to)

+ 9 - 10
packages/app/src/pages/session/session-side-panel.tsx

@@ -23,7 +23,7 @@ import { useLayout } from "@/context/layout"
 import { useSync } from "@/context/sync"
 import { createFileTabListSync } from "@/pages/session/file-tab-scroll"
 import { FileTabContent } from "@/pages/session/file-tabs"
-import { getTabReorderIndex } from "@/pages/session/helpers"
+import { createOpenSessionFileTab, getTabReorderIndex } from "@/pages/session/helpers"
 import { StickyAddButton } from "@/pages/session/review-tab"
 import { setSessionHandoff } from "@/pages/session/handoff"
 
@@ -96,15 +96,14 @@ export function SessionSidePanel(props: {
     if (!view().reviewPanel.opened()) view().reviewPanel.open()
   }
 
-  const openTab = (value: string) => {
-    const next = normalizeTab(value)
-    tabs().open(next)
-
-    const path = file.pathFromTab(next)
-    if (!path) return
-    file.load(path)
-    openReviewPanel()
-  }
+  const openTab = createOpenSessionFileTab({
+    normalizeTab,
+    openTab: tabs().open,
+    pathFromTab: file.pathFromTab,
+    loadFile: file.load,
+    openReviewPanel,
+    setActive: tabs().setActive,
+  })
 
   const contextOpen = createMemo(() => tabs().active() === "context" || tabs().all().includes("context"))
   const openedTabs = createMemo(() =>