Preserve prompt input when creating new session (#4993)

This commit is contained in:
Daniel Gray
2025-12-04 11:12:58 -06:00
committed by GitHub
parent 1d6e3d477b
commit 27c99b46cb
6 changed files with 55 additions and 8 deletions

View File

@@ -32,6 +32,7 @@ import { KVProvider, useKV } from "./context/kv"
import { Provider } from "@/provider/provider"
import { ArgsProvider, useArgs, type Args } from "./context/args"
import open from "open"
import { PromptRefProvider, usePromptRef } from "./context/prompt"
async function getTerminalBackgroundColor(): Promise<"dark" | "light"> {
// can't set raw mode if not a TTY
@@ -119,7 +120,9 @@ export function tui(input: { url: string; args: Args; onExit?: () => Promise<voi
<DialogProvider>
<CommandProvider>
<PromptHistoryProvider>
<App />
<PromptRefProvider>
<App />
</PromptRefProvider>
</PromptHistoryProvider>
</CommandProvider>
</DialogProvider>
@@ -160,6 +163,7 @@ function App() {
const { theme, mode, setMode } = useTheme()
const sync = useSync()
const exit = useExit()
const promptRef = usePromptRef()
createEffect(() => {
console.log(JSON.stringify(route.data))
@@ -225,8 +229,12 @@ function App() {
keybind: "session_new",
category: "Session",
onSelect: () => {
const current = promptRef.current
// Don't require focus - if there's any text, preserve it
const currentPrompt = current?.current?.input ? current.current : undefined
route.navigate({
type: "home",
initialPrompt: currentPrompt,
})
dialog.clear()
},