Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export function createPromptSubmissionState(input: {
prompt: Prompt
context: (ContextItem & { key: string })[]
}) {
const initial = input.target
let target = input.target
let cleared: Prompt | undefined

Expand All @@ -15,6 +16,7 @@ export function createPromptSubmissionState(input: {
context: input.context,
target: () => target,
clear() {
if (initial !== target) initial.reset()
target.reset()
cleared = target.current()
},
Expand Down
17 changes: 17 additions & 0 deletions packages/app/test-browser/prompt-submission-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ describe("prompt submission state", () => {
expect(session.context.items()[0]).toMatchObject({ type: "file", path: "src/index.ts" })
})

test("clears the original first-submit prompt after retargeting", () => {
const workspace = createPromptState()
const session = createPromptState()
workspace.set([{ type: "text", content: "first prompt", start: 0, end: 12 }])
const submission = createPromptSubmissionState({
target: workspace,
prompt: workspace.current(),
context: [],
})

submission.retarget(session)
submission.clear()

expect(workspace.current()[0]).toMatchObject({ type: "text", content: "" })
expect(session.current()[0]).toMatchObject({ type: "text", content: "" })
})

test("does not restore over a prompt edited after submission", () => {
const target = createPromptState()
target.set([{ type: "text", content: "submitted", start: 0, end: 9 }])
Expand Down
Loading