diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 9ab747b1..28e5f98d 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -105,6 +105,7 @@ jobs: run: >- node --import tsx --test packages/ui/src/components/session-list-visibility.test.ts + packages/ui/src/components/unified-picker-path.test.ts packages/ui/src/lib/hooks/use-app-session-capture.test.ts packages/ui/src/lib/message-selection-position.test.ts packages/ui/src/lib/trailing-resync.test.ts diff --git a/packages/ui/src/components/unified-picker-path.test.ts b/packages/ui/src/components/unified-picker-path.test.ts new file mode 100644 index 00000000..ed341d1a --- /dev/null +++ b/packages/ui/src/components/unified-picker-path.test.ts @@ -0,0 +1,21 @@ +import assert from "node:assert/strict" +import test from "node:test" +import { splitDisplayPath } from "./unified-picker-path" + +test("splits paths into file and directory context", () => { + assert.deepEqual(splitDisplayPath("packages/ui/src/components/unified-picker.tsx"), { + name: "unified-picker.tsx", + parent: "components", + directory: "packages/ui/src/components", + }) + assert.deepEqual(splitDisplayPath("src/components/"), { + name: "components/", + parent: "src", + directory: "src", + }) + assert.deepEqual(splitDisplayPath("README.md"), { + name: "README.md", + parent: "", + directory: "", + }) +}) diff --git a/packages/ui/src/components/unified-picker-path.ts b/packages/ui/src/components/unified-picker-path.ts new file mode 100644 index 00000000..a8d92fce --- /dev/null +++ b/packages/ui/src/components/unified-picker-path.ts @@ -0,0 +1,10 @@ +export function splitDisplayPath(path: string) { + const isDirectory = path.endsWith("/") + const parts = path.split("/").filter(Boolean) + const folders = parts.slice(0, -1) + return { + name: parts.length > 0 ? `${parts[parts.length - 1]}${isDirectory ? "/" : ""}` : path, + parent: folders[folders.length - 1] ?? "", + directory: folders.join("/"), + } +} diff --git a/packages/ui/src/components/unified-picker.tsx b/packages/ui/src/components/unified-picker.tsx index 6c9e5837..5c7d74d5 100644 --- a/packages/ui/src/components/unified-picker.tsx +++ b/packages/ui/src/components/unified-picker.tsx @@ -5,6 +5,7 @@ import type { OpencodeClient } from "@opencode-ai/sdk/v2/client" import { serverApi } from "../lib/api-client" import { useI18n } from "../lib/i18n" import { getLogger } from "../lib/logger" +import { splitDisplayPath } from "./unified-picker-path" const log = getLogger("actions") @@ -114,6 +115,7 @@ const UnifiedPicker: Component = (props) => { setTimeout(() => { if (scrollContainerRef) { scrollContainerRef.scrollTop = 0 + scrollContainerRef.scrollLeft = 0 } }, 0) } @@ -585,6 +587,7 @@ const UnifiedPicker: Component = (props) => { (item) => item.type === "file" && item.file.relativePath === file.relativePath, ) const isFolder = file.isDirectory + const displayPath = splitDisplayPath(file.path) return (
= (props) => { /> - {file.path} + + {file.path} + +
)