fix(app): clear original prompt after retarget (#34863)
This commit is contained in:
@@ -7,6 +7,7 @@ export function createPromptSubmissionState(input: {
|
|||||||
prompt: Prompt
|
prompt: Prompt
|
||||||
context: (ContextItem & { key: string })[]
|
context: (ContextItem & { key: string })[]
|
||||||
}) {
|
}) {
|
||||||
|
const initial = input.target
|
||||||
let target = input.target
|
let target = input.target
|
||||||
let cleared: Prompt | undefined
|
let cleared: Prompt | undefined
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ export function createPromptSubmissionState(input: {
|
|||||||
context: input.context,
|
context: input.context,
|
||||||
target: () => target,
|
target: () => target,
|
||||||
clear() {
|
clear() {
|
||||||
|
if (initial !== target) initial.reset()
|
||||||
target.reset()
|
target.reset()
|
||||||
cleared = target.current()
|
cleared = target.current()
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -38,6 +38,23 @@ describe("prompt submission state", () => {
|
|||||||
expect(session.context.items()[0]).toMatchObject({ type: "file", path: "src/index.ts" })
|
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", () => {
|
test("does not restore over a prompt edited after submission", () => {
|
||||||
const target = createPromptState()
|
const target = createPromptState()
|
||||||
target.set([{ type: "text", content: "submitted", start: 0, end: 9 }])
|
target.set([{ type: "text", content: "submitted", start: 0, end: 9 }])
|
||||||
|
|||||||
Reference in New Issue
Block a user