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(() => ({
|
Keymap.createLayer(() => ({
|
||||||
mode: "global",
|
mode: "global",
|
||||||
enabled: props.sessionID !== undefined,
|
|
||||||
commands: [
|
commands: [
|
||||||
{
|
{
|
||||||
id: "session.cd",
|
id: "session.cd",
|
||||||
title: "Change working directory",
|
title: "Change working directory",
|
||||||
slash: { name: "cd", arguments: true },
|
slash: { name: "cd", arguments: true },
|
||||||
run: async (input) => {
|
run: async (input) => {
|
||||||
const sessionID = props.sessionID
|
|
||||||
if (!sessionID) return
|
|
||||||
if (!input?.trim()) {
|
if (!input?.trim()) {
|
||||||
toast.show({ message: "Directory is required", variant: "error" })
|
toast.show({ message: "Directory is required", variant: "error" })
|
||||||
return
|
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
|
await client.api.session
|
||||||
.move({ sessionID, directory: input })
|
.move({ sessionID, directory: input })
|
||||||
.catch((error) =>
|
.catch((error) =>
|
||||||
|
|
|
||||||
|
|
@ -158,6 +158,10 @@ export function usePromptMove(input: { projectID: () => string | undefined; sess
|
||||||
setCreating(false)
|
setCreating(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setDirectory(directory: string, subdirectory: boolean) {
|
||||||
|
setDestination({ type: "directory", directory, subdirectory })
|
||||||
|
}
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
if (!creating()) {
|
if (!creating()) {
|
||||||
setCreatingDots(3)
|
setCreatingDots(3)
|
||||||
|
|
@ -176,6 +180,7 @@ export function usePromptMove(input: { projectID: () => string | undefined; sess
|
||||||
pending,
|
pending,
|
||||||
pendingNew,
|
pendingNew,
|
||||||
progress,
|
progress,
|
||||||
|
setDirectory,
|
||||||
startSubmit,
|
startSubmit,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue