Clear pasted and picked attachments from the composer at send

The chips stayed until the server accepted the prompt, a few seconds
after the sent turn already showed the files. They now leave the field
with the text as the prompt goes out; a refusal that gives the composer
its text back restores the same chips.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 10:45:28 +00:00
parent 33874005c4
commit a70a4a3c86
2 changed files with 19 additions and 8 deletions
@@ -710,9 +710,9 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
} }
/// Builds the chips' exact wire parts and hands them to the composer with the /// Builds the chips' exact wire parts and hands them to the composer with the
/// draft's text and operation id. The chips stay while the prompt is in /// draft's text and operation id. The chips clear with the text as the
/// flight so a refusal leaves the draft and its files together; only an /// prompt leaves; a refusal that restores the text restores them too, so
/// accepted prompt clears them. /// the draft and its files stay together.
Future<void> _send({int sendAt = 0}) async { Future<void> _send({int sendAt = 0}) async {
final composer = widget.composer; final composer = widget.composer;
if (_uploading || composer.sending || composer.draft.trim().isEmpty) { if (_uploading || composer.sending || composer.draft.trim().isEmpty) {
@@ -760,9 +760,20 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
if (_uploading) setState(() => _uploading = false); if (_uploading) setState(() => _uploading = false);
// Keep the caret in the field while the prompt is in flight, as before. // Keep the caret in the field while the prompt is in flight, as before.
_focus.requestFocus(); _focus.requestFocus();
// Acceptance (here or through the bubble's Retry) clears the chips via // The chips leave the field with the text, at once: the sent turn already
// the composer's accepted-send count. // shows the files. A refusal that gives the composer its text back puts
await composer.send(attachments: parts, sendAt: sendAt); // the same chips back with it.
final sentText = composer.draft;
final keptAttachments = List<ChatAttachment>.of(_attachments.attachments);
final keptBytes = List<Uint8List>.of(_bytes);
if (keptAttachments.isNotEmpty) {
setState(() => _replaceAttachments(const [], const []));
}
final accepted = await composer.send(attachments: parts, sendAt: sendAt);
if (!mounted || accepted || keptAttachments.isEmpty) return;
if (_attachments.isEmpty && composer.draft == sentText) {
setState(() => _replaceAttachments(keptAttachments, keptBytes));
}
} }
/// Adds the operator's explicit selection through the host seam. A dismissed /// Adds the operator's explicit selection through the host seam. A dismissed
@@ -356,10 +356,10 @@ void main() {
expect(primary().onPressed, isNull); expect(primary().onPressed, isNull);
expect(attach().onPressed, isNull); expect(attach().onPressed, isNull);
expect(gateway.promptBodies.single['attachments'], _wireParts([file])); expect(gateway.promptBodies.single['attachments'], _wireParts([file]));
// The chips stay until the prompt is accepted. // The chips leave the field with the text as the prompt goes out.
expect( expect(
find.byKey(const Key('chat-composer-attachments')), find.byKey(const Key('chat-composer-attachments')),
findsOneWidget, findsNothing,
); );
reply.complete(const {}); reply.complete(const {});