mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
fix(app): preserve composer edits made while selection commits
This commit is contained in:
parent
26059a1f11
commit
469ffd489b
3 changed files with 46 additions and 1 deletions
|
|
@ -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 }) {
|
||||
|
|
|
|||
|
|
@ -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[] = []
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue