@@ -56,7 +56,8 @@ export const ProposedPlanCard = memo(function ProposedPlanCard({ |
56 | 56 | const [expanded, setExpanded] = useState(false); |
57 | 57 | const canWriteFiles = useEnvironmentScope(environmentId, AuthFilesystemWriteScope); |
58 | 58 | const [isSaveDialogOpen, setIsSaveDialogOpen] = useState(false); |
59 | | - const [savePath, setSavePath] = useState(""); |
| 59 | + // The path last submitted, so reopening the dialog offers it again. |
| 60 | + const [lastSavePath, setLastSavePath] = useState(""); |
60 | 61 | const [isSavingToWorkspace, setIsSavingToWorkspace] = useState(false); |
61 | 62 | const writeProjectFile = useAtomCommand(projectEnvironment.writeFile, { |
62 | 63 | reportFailure: false, |
@@ -73,7 +74,6 @@ export const ProposedPlanCard = memo(function ProposedPlanCard({ |
73 | 74 | ); |
74 | 75 | }, |
75 | 76 | }); |
76 | | - const savePathInputId = useId(); |
77 | 77 | const title = proposedPlanTitle(planMarkdown) ?? "Proposed plan"; |
78 | 78 | const lineCount = planMarkdown.split("\n").length; |
79 | 79 | const canCollapse = planMarkdown.length > 900 || lineCount > 20; |
@@ -109,11 +109,10 @@ export const ProposedPlanCard = memo(function ProposedPlanCard({ |
109 | 109 | ); |
110 | 110 | return; |
111 | 111 | } |
112 | | - setSavePath((existing) => (existing.length > 0 ? existing : downloadFilename)); |
113 | 112 | setIsSaveDialogOpen(true); |
114 | 113 | }; |
115 | 114 |
|
116 | | - const handleSaveToWorkspace = () => { |
| 115 | + const handleSaveToWorkspace = (savePath: string) => { |
117 | 116 | const relativePath = savePath.trim(); |
118 | 117 | if (!workspaceRoot || !readEnvironmentScope(environmentId, AuthFilesystemWriteScope)) { |
119 | 118 | return; |
@@ -126,6 +125,7 @@ export const ProposedPlanCard = memo(function ProposedPlanCard({ |
126 | 125 | return; |
127 | 126 | } |
128 | 127 |
|
| 128 | + setLastSavePath(savePath); |
129 | 129 | setIsSavingToWorkspace(true); |
130 | 130 | void (async () => { |
131 | 131 | const result = await writeProjectFile({ |
@@ -241,45 +241,71 @@ export const ProposedPlanCard = memo(function ProposedPlanCard({ |
241 | 241 | } |
242 | 242 | }} |
243 | 243 | > |
| 244 | + {/* The form owns the path so a keystroke re-renders it, not the dialog chrome. */} |
244 | 245 | <DialogPopup className="max-w-xl"> |
245 | | - <DialogHeader> |
246 | | - <DialogTitle>Save plan to workspace</DialogTitle> |
247 | | - <DialogDescription> |
248 | | - Enter a path relative to <code>{workspaceRoot ?? "the workspace"}</code>. |
249 | | - </DialogDescription> |
250 | | - </DialogHeader> |
251 | | - <DialogPanel> |
252 | | - <label htmlFor={savePathInputId} className="grid gap-1.5"> |
253 | | - <span className="text-xs font-medium text-foreground">Workspace path</span> |
254 | | - <Input |
255 | | - id={savePathInputId} |
256 | | - value={savePath} |
257 | | - onChange={(event) => setSavePath(event.target.value)} |
258 | | - placeholder={downloadFilename} |
259 | | - spellCheck={false} |
260 | | - disabled={isSavingToWorkspace} |
261 | | - /> |
262 | | - </label> |
263 | | - </DialogPanel> |
264 | | - <DialogFooter> |
265 | | - <Button |
266 | | - variant="outline" |
267 | | - size="sm" |
268 | | - onClick={() => setIsSaveDialogOpen(false)} |
269 | | - disabled={isSavingToWorkspace} |
270 | | - > |
271 | | - Cancel |
272 | | - </Button> |
273 | | - <Button |
274 | | - size="sm" |
275 | | - onClick={() => void handleSaveToWorkspace()} |
276 | | - disabled={!canWriteFiles || isSavingToWorkspace} |
277 | | - > |
278 | | - {isSavingToWorkspace ? "Saving..." : "Save"} |
279 | | - </Button> |
280 | | - </DialogFooter> |
| 246 | + <SavePlanToWorkspaceForm |
| 247 | + initialPath={lastSavePath || downloadFilename} |
| 248 | + placeholder={downloadFilename} |
| 249 | + workspaceRoot={workspaceRoot} |
| 250 | + canWriteFiles={canWriteFiles} |
| 251 | + saving={isSavingToWorkspace} |
| 252 | + onCancel={() => setIsSaveDialogOpen(false)} |
| 253 | + onSave={handleSaveToWorkspace} |
| 254 | + /> |
281 | 255 | </DialogPopup> |
282 | 256 | </Dialog> |
283 | 257 | </div> |
284 | 258 | ); |
285 | 259 | }); |
| 260 | + |
| 261 | +function SavePlanToWorkspaceForm({ |
| 262 | + initialPath, |
| 263 | + placeholder, |
| 264 | + workspaceRoot, |
| 265 | + canWriteFiles, |
| 266 | + saving, |
| 267 | + onCancel, |
| 268 | + onSave, |
| 269 | +}: { |
| 270 | + initialPath: string; |
| 271 | + placeholder: string; |
| 272 | + workspaceRoot: string | undefined; |
| 273 | + canWriteFiles: boolean; |
| 274 | + saving: boolean; |
| 275 | + onCancel: () => void; |
| 276 | + onSave: (path: string) => void; |
| 277 | +}) { |
| 278 | + const [savePath, setSavePath] = useState(initialPath); |
| 279 | + const savePathInputId = useId(); |
| 280 | + return ( |
| 281 | + <> |
| 282 | + <DialogHeader> |
| 283 | + <DialogTitle>Save plan to workspace</DialogTitle> |
| 284 | + <DialogDescription> |
| 285 | + Enter a path relative to <code>{workspaceRoot ?? "the workspace"}</code>. |
| 286 | + </DialogDescription> |
| 287 | + </DialogHeader> |
| 288 | + <DialogPanel> |
| 289 | + <label htmlFor={savePathInputId} className="grid gap-1.5"> |
| 290 | + <span className="text-xs font-medium text-foreground">Workspace path</span> |
| 291 | + <Input |
| 292 | + id={savePathInputId} |
| 293 | + value={savePath} |
| 294 | + onChange={(event) => setSavePath(event.target.value)} |
| 295 | + placeholder={placeholder} |
| 296 | + spellCheck={false} |
| 297 | + disabled={saving} |
| 298 | + /> |
| 299 | + </label> |
| 300 | + </DialogPanel> |
| 301 | + <DialogFooter> |
| 302 | + <Button variant="outline" size="sm" onClick={onCancel} disabled={saving}> |
| 303 | + Cancel |
| 304 | + </Button> |
| 305 | + <Button size="sm" onClick={() => onSave(savePath)} disabled={!canWriteFiles || saving}> |
| 306 | + {saving ? "Saving..." : "Save"} |
| 307 | + </Button> |
| 308 | + </DialogFooter> |
| 309 | + </> |
| 310 | + ); |
| 311 | +} |