Merge branch 'main' into flutter/chat-cmd-stop
This commit is contained in:
@@ -8,6 +8,7 @@ import '../../../core/api_gateway.dart';
|
||||
import '../domain/chat_attachment_draft.dart';
|
||||
import '../domain/chat_attachment_picker.dart';
|
||||
import '../domain/chat_attachment_wire.dart';
|
||||
import '../domain/chat_clipboard_paste.dart';
|
||||
import '../domain/chat_commands.dart';
|
||||
import '../ui/sessions/chat_adaptive.dart';
|
||||
import 'chat_command_palette.dart';
|
||||
@@ -50,13 +51,16 @@ const String chatQueuedNotice =
|
||||
/// their names are shown with the host's own remove action and the bounded
|
||||
/// draft owns every refusal. Send carries the chips as the landed wire parts,
|
||||
/// keeps them until the prompt is accepted and leaves them in place on a
|
||||
/// refusal; paste is not wired.
|
||||
/// refusal. Pasting files takes the same draft path as the picker; pasting text
|
||||
/// stays with the host field, so its caret, selection and draft behave exactly
|
||||
/// as typing does.
|
||||
class ChatComposerBar extends StatefulWidget {
|
||||
const ChatComposerBar({
|
||||
super.key,
|
||||
required this.composer,
|
||||
required this.running,
|
||||
this.picker,
|
||||
this.paste,
|
||||
});
|
||||
|
||||
final ChatComposerController composer;
|
||||
@@ -67,6 +71,9 @@ class ChatComposerBar extends StatefulWidget {
|
||||
/// The host picker seam; production uses [hostChatAttachmentPicker].
|
||||
final ChatAttachmentPicker? picker;
|
||||
|
||||
/// The host clipboard-file seam; production uses [hostChatClipboardPaste].
|
||||
final ChatClipboardPaste? paste;
|
||||
|
||||
@override
|
||||
State<ChatComposerBar> createState() => _ChatComposerBarState();
|
||||
}
|
||||
@@ -99,11 +106,15 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
bool _commandFailed = false;
|
||||
|
||||
ChatAttachmentPicker get _picker => widget.picker ?? hostChatAttachmentPicker;
|
||||
ChatClipboardPaste get _paste => widget.paste ?? hostChatClipboardPaste;
|
||||
|
||||
ChatPasteUnsubscribe? _stopPaste;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
widget.composer.addListener(_syncDraft);
|
||||
_listenForPaste();
|
||||
unawaited(widget.composer.loadDraft());
|
||||
}
|
||||
|
||||
@@ -115,6 +126,42 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
widget.composer.addListener(_syncDraft);
|
||||
_syncDraft();
|
||||
}
|
||||
if (oldWidget.paste != widget.paste) {
|
||||
_stopListeningForPaste();
|
||||
_listenForPaste();
|
||||
}
|
||||
}
|
||||
|
||||
void _listenForPaste() {
|
||||
if (!_paste.isSupported) return;
|
||||
_stopPaste = _paste.listen(
|
||||
onFiles: _onPastedFiles,
|
||||
canAccept: _canAcceptPaste,
|
||||
onError: _onPasteError,
|
||||
);
|
||||
}
|
||||
|
||||
void _stopListeningForPaste() {
|
||||
final stop = _stopPaste;
|
||||
_stopPaste = null;
|
||||
stop?.call();
|
||||
}
|
||||
|
||||
/// A pasted file is taken only while this composer owns the field and no
|
||||
/// prompt is in flight, which is the same window as the attach control. The
|
||||
/// host checks this before it suppresses the paste's default behaviour, so a
|
||||
/// paste elsewhere is never swallowed.
|
||||
bool _canAcceptPaste() =>
|
||||
mounted && _focus.hasFocus && !widget.composer.sending;
|
||||
|
||||
void _onPastedFiles(List<ChatPickedFile> files) {
|
||||
if (!mounted) return;
|
||||
_addFiles(files);
|
||||
}
|
||||
|
||||
void _onPasteError(Object error) {
|
||||
if (!mounted) return;
|
||||
setState(() => _attachmentError = '$error');
|
||||
}
|
||||
|
||||
/// External draft changes (saved-draft load, send clear, refusal restore)
|
||||
@@ -355,12 +402,19 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
return;
|
||||
}
|
||||
if (!mounted || files == null) return;
|
||||
final picked = files;
|
||||
_addFiles(files);
|
||||
}
|
||||
|
||||
/// Adds each file through the landed attachment draft. A refusal keeps every
|
||||
/// attachment already in the draft and shows the draft's own words; the
|
||||
/// refused file's bytes are never retained. Picking and pasting share this
|
||||
/// path so both apply the same name and 1 MiB decisions.
|
||||
void _addFiles(List<ChatPickedFile> files) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_attachmentError = null;
|
||||
for (final file in picked) {
|
||||
final attachment = file.attachment;
|
||||
final refusal = _attachments.add(attachment);
|
||||
for (final file in files) {
|
||||
final refusal = _attachments.add(file.attachment);
|
||||
if (refusal != null) {
|
||||
_attachmentError = refusal.message;
|
||||
} else {
|
||||
@@ -410,6 +464,7 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_stopListeningForPaste();
|
||||
widget.composer.removeListener(_syncDraft);
|
||||
_text.dispose();
|
||||
_focus.dispose();
|
||||
|
||||
Reference in New Issue
Block a user