fix(app): preserve composer edits made while selection commits

This commit is contained in:
Kit Langton 2026-10-13 04:37:47 +00:00
parent 26059a1f11
commit 469ffd489b
3 changed files with 46 additions and 1 deletions

View file

@ -27,9 +27,20 @@ export function createComposerSubmission(input: {
// A preparing session may already have an unsent follow-up in its promoted composer.
if (preserveDraft && target.current().some((part) => isAttachment(part) || part.content.length > 0))
following = clonePrompt(target.current())
if (!following) target.reset()
cleared = target.current()
return
}
if (!following) target.reset()
if (target.current() !== before) {
cleared = before
return
}
target.reset()
cleared = target.current()
},
retarget(next: ComposerStateTarget, options?: { preserveDraft?: boolean }) {

View file

@ -347,6 +347,37 @@ describe("Composer submission", () => {
expect(state.retry.current()?.id).toMatch(/^msg_/)
})
test("preserves edits typed while model selection is in flight and sends the captured snapshot", async () => {
const state = createMemoryComposerState({ prompt: "ship it" }).capture()
const switching = Promise.withResolvers<void>()
const committed = Promise.withResolvers<void>()
const sent: string[] = []
const target = session({
calls: [],
current: () => ({ agent: "build", model: { providerID: "provider-1", id: "model-1", variant: "balanced" } }),
switchModel: async () => {
switching.resolve()
await committed.promise
},
prompt: async (value) => {
sent.push(value.text)
},
})
const submission = submitInput(active(state, target))
const first = submission.submit(new Event("submit"))
await switching.promise
const edited: Prompt = [{ type: "text", content: "ship it and also run tests", start: 0, end: 26 }]
state.set(edited, 26)
committed.resolve()
await first
expect(sent).toEqual(["ship it"])
expect(state.current()).toEqual(edited)
})
test("applies the captured agent and model before a custom command without passing over its overrides", async () => {
const state = createMemoryComposerState({ prompt: "/review changes" }).capture()
const calls: string[] = []

View file

@ -391,7 +391,10 @@ function currentSelection(input: ComposerSubmitInput): ComposerSelection | undef
}
function clearSubmission(input: ComposerSubmitInput, submission: ReturnType<typeof createComposerSubmission>) {
const unchanged = submission.unchanged()
submission.clear()
if (!unchanged) return
submission.target().mode.set("normal")
input.setMode("normal")
input.closePopover()