From a70a4a3c8625c82742ab57bb6bbdcbd8a01c542c Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Wed, 25 Nov 2026 10:45:28 +0000 Subject: [PATCH] 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 --- .../chat/conversation/chat_composer_bar.dart | 23 ++++++++++++++----- .../chat_composer_attachment_send_test.dart | 4 ++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/lib/features/chat/conversation/chat_composer_bar.dart b/app/lib/features/chat/conversation/chat_composer_bar.dart index f3b11c00..9c297813 100644 --- a/app/lib/features/chat/conversation/chat_composer_bar.dart +++ b/app/lib/features/chat/conversation/chat_composer_bar.dart @@ -710,9 +710,9 @@ class _ChatComposerBarState extends State { } /// 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 - /// flight so a refusal leaves the draft and its files together; only an - /// accepted prompt clears them. + /// draft's text and operation id. The chips clear with the text as the + /// prompt leaves; a refusal that restores the text restores them too, so + /// the draft and its files stay together. Future _send({int sendAt = 0}) async { final composer = widget.composer; if (_uploading || composer.sending || composer.draft.trim().isEmpty) { @@ -760,9 +760,20 @@ class _ChatComposerBarState extends State { if (_uploading) setState(() => _uploading = false); // Keep the caret in the field while the prompt is in flight, as before. _focus.requestFocus(); - // Acceptance (here or through the bubble's Retry) clears the chips via - // the composer's accepted-send count. - await composer.send(attachments: parts, sendAt: sendAt); + // The chips leave the field with the text, at once: the sent turn already + // shows the files. A refusal that gives the composer its text back puts + // the same chips back with it. + final sentText = composer.draft; + final keptAttachments = List.of(_attachments.attachments); + final keptBytes = List.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 diff --git a/app/test/features/chat/conversation/chat_composer_attachment_send_test.dart b/app/test/features/chat/conversation/chat_composer_attachment_send_test.dart index 627c3d31..ba4ec2ab 100644 --- a/app/test/features/chat/conversation/chat_composer_attachment_send_test.dart +++ b/app/test/features/chat/conversation/chat_composer_attachment_send_test.dart @@ -356,10 +356,10 @@ void main() { expect(primary().onPressed, isNull); expect(attach().onPressed, isNull); 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( find.byKey(const Key('chat-composer-attachments')), - findsOneWidget, + findsNothing, ); reply.complete(const {});