mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-30 12:13:30 +00:00
fix(tui): support cd before session creation (#39555)
This commit is contained in:
parent
f7ea2fc346
commit
4f871906bc
2 changed files with 23 additions and 3 deletions
|
|
@ -216,19 +216,34 @@ export function Prompt(props: PromptProps) {
|
|||
})
|
||||
Keymap.createLayer(() => ({
|
||||
mode: "global",
|
||||
enabled: props.sessionID !== undefined,
|
||||
commands: [
|
||||
{
|
||||
id: "session.cd",
|
||||
title: "Change working directory",
|
||||
slash: { name: "cd", arguments: true },
|
||||
run: async (input) => {
|
||||
const sessionID = props.sessionID
|
||||
if (!sessionID) return
|
||||
if (!input?.trim()) {
|
||||
toast.show({ message: "Directory is required", variant: "error" })
|
||||
return
|
||||
}
|
||||
const sessionID = props.sessionID
|
||||
if (!sessionID) {
|
||||
const value = input.trim()
|
||||
const expanded =
|
||||
value === "~" ? paths.home : value.startsWith("~/") ? path.join(paths.home, value.slice(2)) : value
|
||||
const directory = path.resolve(
|
||||
currentLocation.current?.directory ?? data.location.default().directory,
|
||||
expanded,
|
||||
)
|
||||
const location = await client.api.location.get({ location: { directory } }).catch((error) => {
|
||||
toast.show({ title: "Failed to change directory", message: errorMessage(error), variant: "error" })
|
||||
return undefined
|
||||
})
|
||||
if (!location) return
|
||||
move.setDirectory(location.directory, location.directory !== location.project.directory)
|
||||
currentLocation.set(location)
|
||||
return
|
||||
}
|
||||
await client.api.session
|
||||
.move({ sessionID, directory: input })
|
||||
.catch((error) =>
|
||||
|
|
|
|||
|
|
@ -158,6 +158,10 @@ export function usePromptMove(input: { projectID: () => string | undefined; sess
|
|||
setCreating(false)
|
||||
}
|
||||
|
||||
function setDirectory(directory: string, subdirectory: boolean) {
|
||||
setDestination({ type: "directory", directory, subdirectory })
|
||||
}
|
||||
|
||||
createEffect(() => {
|
||||
if (!creating()) {
|
||||
setCreatingDots(3)
|
||||
|
|
@ -176,6 +180,7 @@ export function usePromptMove(input: { projectID: () => string | undefined; sess
|
|||
pending,
|
||||
pendingNew,
|
||||
progress,
|
||||
setDirectory,
|
||||
startSubmit,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue