GeezerVison is showing github.com — fix(app): worktree selection should navigate to worktree · flowingboy/opencode@d119167
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/app/src/components/session/session-new-view.tsx +10-3Lines changed: 10 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -23,11 +23,18 @@ export function NewSessionView(props: NewSessionViewProps) { | 23 | 23 | if (options().includes(selection)) return selection | 24 | 24 | return MAIN_WORKTREE | 25 | 25 | }) | | 26 | + const projectRoot = createMemo(() => sync.project?.worktree ?? sync.data.path.directory) | | 27 | + const isWorktree = createMemo(() => { | | 28 | + const project = sync.project | | 29 | + if (!project) return false | | 30 | + return sync.data.path.directory !== project.worktree | | 31 | + }) | 26 | 32 |
| 27 | 33 | const label = (value: string) => { | 28 | 34 | if (value === MAIN_WORKTREE) { | | 35 | + if (isWorktree()) return "Main branch" | 29 | 36 | const branch = sync.data.vcs?.branch | 30 | | - if (branch) return `Current branch (${branch})` | | 37 | + if (branch) return `Main branch (${branch})` | 31 | 38 | return "Main branch" | 32 | 39 | } | 33 | 40 |
| @@ -42,8 +49,8 @@ export function NewSessionView(props: NewSessionViewProps) { | 42 | 49 | <div class="flex justify-center items-center gap-3"> | 43 | 50 | <Icon name="folder" size="small" /> | 44 | 51 | <div class="text-12-medium text-text-weak"> | 45 | | - {getDirectory(sync.data.path.directory)} | 46 | | - <span class="text-text-strong">{getFilename(sync.data.path.directory)}</span> | | 52 | + {getDirectory(projectRoot())} | | 53 | + <span class="text-text-strong">{getFilename(projectRoot())}</span> | 47 | 54 | </div> | 48 | 55 | </div> | 49 | 56 | <div class="flex justify-center items-center gap-1"> | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/context/layout.tsx +41-7Lines changed: 41 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { createStore, produce } from "solid-js/store" | 2 | | -import { batch, createMemo, onMount } from "solid-js" | | 2 | +import { batch, createEffect, createMemo, onMount } from "solid-js" | 3 | 3 | import { createSimpleContext } from "@opencode-ai/ui/context" | 4 | 4 | import { useGlobalSync } from "./global-sync" | 5 | 5 | import { useGlobalSDK } from "./global-sdk" | @@ -91,8 +91,8 @@ export const { use: useLayout, provider: LayoutProvider } = createSimpleContext( | 91 | 91 | : globalSync.data.project.find((x) => x.worktree === project.worktree) | 92 | 92 | return [ | 93 | 93 | { | 94 | | - ...project, | 95 | 94 | ...(metadata ?? {}), | | 95 | + ...project, | 96 | 96 | icon: { url: metadata?.icon?.url, color: metadata?.icon?.color }, | 97 | 97 | }, | 98 | 98 | ] | @@ -109,6 +109,41 @@ export const { use: useLayout, provider: LayoutProvider } = createSimpleContext( | 109 | 109 | return project | 110 | 110 | } | 111 | 111 |
| | 112 | + const roots = createMemo(() => { | | 113 | + const map = new Map<string, string>() | | 114 | + for (const project of globalSync.data.project) { | | 115 | + const sandboxes = project.sandboxes ?? [] | | 116 | + for (const sandbox of sandboxes) { | | 117 | + map.set(sandbox, project.worktree) | | 118 | + } | | 119 | + } | | 120 | + return map | | 121 | + }) | | 122 | + | | 123 | + createEffect(() => { | | 124 | + const map = roots() | | 125 | + if (map.size === 0) return | | 126 | + | | 127 | + const projects = server.projects.list() | | 128 | + const seen = new Set(projects.map((project) => project.worktree)) | | 129 | + | | 130 | + batch(() => { | | 131 | + for (const project of projects) { | | 132 | + const root = map.get(project.worktree) | | 133 | + if (!root) continue | | 134 | + | | 135 | + server.projects.close(project.worktree) | | 136 | + | | 137 | + if (!seen.has(root)) { | | 138 | + server.projects.open(root) | | 139 | + seen.add(root) | | 140 | + } | | 141 | + | | 142 | + if (project.expanded) server.projects.expand(root) | | 143 | + } | | 144 | + }) | | 145 | + }) | | 146 | + | 112 | 147 | const enriched = createMemo(() => server.projects.list().flatMap(enrich)) | 113 | 148 | const list = createMemo(() => enriched().flatMap(colorize)) | 114 | 149 |
| @@ -125,11 +160,10 @@ export const { use: useLayout, provider: LayoutProvider } = createSimpleContext( | 125 | 160 | projects: { | 126 | 161 | list, | 127 | 162 | open(directory: string) { | 128 | | - if (server.projects.list().find((x) => x.worktree === directory)) { | 129 | | - return | 130 | | - } | 131 | | - globalSync.project.loadSessions(directory) | 132 | | - server.projects.open(directory) | | 163 | + const root = roots().get(directory) ?? directory | | 164 | + if (server.projects.list().find((x) => x.worktree === root)) return | | 165 | + globalSync.project.loadSessions(root) | | 166 | + server.projects.open(root) | 133 | 167 | }, | 134 | 168 | close(directory: string) { | 135 | 169 | server.projects.close(directory) | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/pages/session.tsx +25-5Lines changed: 25 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { For, onCleanup, Show, Match, Switch, createMemo, createEffect, on, batch } from "solid-js" | | 1 | +import { For, onCleanup, Show, Match, Switch, createMemo, createEffect, on } from "solid-js" | 2 | 2 | import { createMediaQuery } from "@solid-primitives/media" | 3 | 3 | import { Dynamic } from "solid-js/web" | 4 | 4 | import { useLocal } from "@/context/local" | @@ -24,7 +24,7 @@ import { useSync } from "@/context/sync" | 24 | 24 | import { useTerminal, type LocalPTY } from "@/context/terminal" | 25 | 25 | import { useLayout } from "@/context/layout" | 26 | 26 | import { Terminal } from "@/components/terminal" | 27 | | -import { checksum, base64Decode } from "@opencode-ai/util/encode" | | 27 | +import { checksum, base64Encode, base64Decode } from "@opencode-ai/util/encode" | 28 | 28 | import { useDialog } from "@opencode-ai/ui/context/dialog" | 29 | 29 | import { DialogSelectFile } from "@/components/dialog-select-file" | 30 | 30 | import { DialogSelectModel } from "@/components/dialog-select-model" | @@ -250,6 +250,13 @@ export default function Page() { | 250 | 250 | newSessionWorktree: "main", | 251 | 251 | }) | 252 | 252 |
| | 253 | + const newSessionWorktree = createMemo(() => { | | 254 | + if (store.newSessionWorktree === "create") return "create" | | 255 | + const project = sync.project | | 256 | + if (project && sync.data.path.directory !== project.worktree) return sync.data.path.directory | | 257 | + return "main" | | 258 | + }) | | 259 | + | 253 | 260 | const activeMessage = createMemo(() => { | 254 | 261 | if (!store.messageId) return lastUserMessage() | 255 | 262 | const found = visibleUserMessages()?.find((m) => m.id === store.messageId) | @@ -866,8 +873,21 @@ export default function Page() { | 866 | 873 | </Match> | 867 | 874 | <Match when={true}> | 868 | 875 | <NewSessionView | 869 | | - worktree={store.newSessionWorktree} | 870 | | - onWorktreeChange={(value) => setStore("newSessionWorktree", value)} | | 876 | + worktree={newSessionWorktree()} | | 877 | + onWorktreeChange={(value) => { | | 878 | + if (value === "create") { | | 879 | + setStore("newSessionWorktree", value) | | 880 | + return | | 881 | + } | | 882 | + | | 883 | + setStore("newSessionWorktree", "main") | | 884 | + | | 885 | + const target = value === "main" ? sync.project?.worktree : value | | 886 | + if (!target) return | | 887 | + if (target === sync.data.path.directory) return | | 888 | + layout.projects.open(target) | | 889 | + navigate(`/${base64Encode(target)}/session`) | | 890 | + }} | 871 | 891 | /> | 872 | 892 | </Match> | 873 | 893 | </Switch> | @@ -885,7 +905,7 @@ export default function Page() { | 885 | 905 | ref={(el) => { | 886 | 906 | inputRef = el | 887 | 907 | }} | 888 | | - newSessionWorktree={store.newSessionWorktree} | | 908 | + newSessionWorktree={newSessionWorktree()} | 889 | 909 | onNewSessionWorktreeReset={() => setStore("newSessionWorktree", "main")} | 890 | 910 | /> | 891 | 911 | </div> | |
|