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:
@@ -710,9 +710,9 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
}
|
||||
|
||||
/// 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<void> _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<ChatComposerBar> {
|
||||
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<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
|
||||
|
||||
@@ -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 {});
|
||||
|
||||
Reference in New Issue
Block a user