72 lines
3.6 KiB
Markdown
72 lines
3.6 KiB
Markdown
# Composer paste
|
|
|
|
Files and text can be pasted into the chat composer. Pasted files take the same
|
|
landed attachment draft path as the picker; text paste stays with the host field
|
|
and behaves exactly like typing.
|
|
|
|
## Files
|
|
|
|
- `lib/features/chat/domain/chat_clipboard_paste.dart` — the host seam
|
|
(`ChatClipboardPaste.listen(onFiles, canAccept, onError)`), the web client's
|
|
nameless-file name (`pasted-<n>.<mime subtype>`, `jpeg` → `jpg`, `bin`
|
|
fallback), and the running host's source.
|
|
- `lib/features/chat/domain/chat_clipboard_paste_web.dart` — a document-level
|
|
`paste` listener using `dart:js_interop` (JS and Wasm targets). It collects the
|
|
clipboard's file items synchronously, asks the composer whether it can take
|
|
them, consumes only that file paste (`preventDefault`), then reads the bytes
|
|
and hands back `ChatPickedFile`s. A text-only paste is never consumed.
|
|
Readable files are delivered before a partial read's failure, so the kept
|
|
files cannot clear the error line.
|
|
`DataTransferItemList` is indexed (`items[i]`), not a method list like
|
|
`FileList`; the first browser run caught the wrong `item()` call.
|
|
- `lib/features/chat/domain/chat_clipboard_paste_stub.dart` — non-web host: text
|
|
paste stays native, and the file-paste capability is reported as unsupported
|
|
instead of pretending it worked.
|
|
- `lib/features/chat/conversation/chat_composer_bar.dart` — subscribes once per
|
|
composer, unsubscribes on source replacement and dispose, and routes both
|
|
picker and paste files through `_addFiles`, so the landed
|
|
`ChatAttachmentDraft.add` owns the blank-name and 1 MiB decisions. Paste is
|
|
accepted only while this composer's field has focus and no prompt is in
|
|
flight, the same window as the attach control. No layout was changed.
|
|
|
|
## Checks run
|
|
|
|
- `flutter test test/features/chat` — 367 passed.
|
|
- `flutter test` — 1591 passed.
|
|
- `flutter test test/features/chat/conversation/chat_composer_paste_test.dart
|
|
test/features/chat/domain/chat_clipboard_paste_test.dart` — 14 passed.
|
|
- `flutter analyze` — no issues.
|
|
- `flutter build web` — built (the web seam compiles for the JS target; the
|
|
build also reports a successful Wasm dry run).
|
|
- `dart format` on touched Dart files — clean.
|
|
|
|
## Browser evidence
|
|
|
|
`tool/chat_paste_probe.mjs` builds the existing `tool/chat_composer_probe_entry.dart`
|
|
fixture, serves it on an OS-assigned loopback port, and drives real Chrome over
|
|
CDP. It dispatches native `ClipboardEvent`s carrying a `DataTransfer` at the
|
|
focused editing element. Result:
|
|
|
|
- a text-only paste is **not** intercepted (`defaultPrevented: false`);
|
|
- a file paste is consumed (`defaultPrevented: true`), shows a `shot.png` chip,
|
|
and leaves the typed draft `keep me` untouched;
|
|
- a 1 MiB + 1 byte file shows the exact draft refusal and adds no `huge.bin`
|
|
chip while the existing chip stays;
|
|
- a nameless `image/png` clipboard file shows as `pasted-1.png`.
|
|
|
|
Captures (in the run's shared artifacts, `public/paste-probe/`):
|
|
`paste-file-chip.png`, `paste-over-limit.png`, `paste-nameless-file.png`.
|
|
|
|
The synthetic browser paste cannot exercise Chrome's default text insertion, so
|
|
the text caret/selection/draft assertion is a widget test that sends the
|
|
platform's own editing update to the field. The browser check proves the listener
|
|
does not consume text-only pastes.
|
|
|
|
## Limits
|
|
|
|
- Web only, as required. Android/iOS/desktop were not built or tested; on those
|
|
hosts text paste stays native and pasted files remain unsupported until a
|
|
native clipboard-file seam exists.
|
|
- Attachments stay memory-only and are not restored with a draft, matching the
|
|
landed draft store and the web client.
|