Files
pipelines/app/notes/chat-unfocused-paste.md
T

36 lines
4.1 KiB
Markdown

# Unfocused chat paste
Text paste routes to the active visible chat composer from transcript/background chrome. Native Cmd/Ctrl+V uses a single controlled Clipboard read when that composer is unfocused. Web uses the browser paste event without another clipboard read. Focused active composers retain native text insertion; another Flutter search/rename editor or external DOM editor retains its own paste. A stale inactive composer cannot swallow active-pane paste.
Routing combines Flutter focus ownership with DOM composed-path and open-shadow-root checks. Engine shared `flt-text-editing` elements and accessibility-mode inputs directly owned by `flt-semantics` remain eligible for the Flutter ownership check. Opaque external custom-element/iframe focus is conservatively left native. File/image paste follows the existing web attachment path, including focused accessibility-mode composers. Native file clipboard remains unsupported as before.
Verification:
- 22 focused VM tests passed under `tool/memwatch/full.sh 'test/features/chat/conversation/chat_unfocused_paste_routing_test.dart test/features/chat/conversation/chat_composer_paste_test.dart test/features/chat/domain/chat_clipboard_paste_test.dart'`, `/tmp/memwatch/out.6cFRrZ`. Real composer wiring exercises Cmd/Ctrl+V, another editor, focused active composer exactly once, inactive focused composer and file/text acceptance. Clipboard is mocked through the platform channel; no host clipboard access.
- 7 Chrome tests passed under `tool/memwatch/full.sh 'test/features/chat/domain/chat_clipboard_paste_web_test.dart --platform chrome'`, `/tmp/memwatch/out.RK4wSb`. Real synthetic ClipboardEvent/DataTransfer covers text/files/images, external textarea, open and closed shadows, Flutter eligibility and capture ordering, and unclassed semantics editor files.
- `tool/analyze.sh` clean: `flutter-analyze.4A4P1A`; `git diff --check` clean. Fixture web release build succeeded using `tool/search_selection_probe_entry.dart`.
- Full app browser fixture evidence: `/tmp/review/unfocused-paste-final/` and `/tmp/unfocused-paste-capture.json`. Uses in-process fixtures, synthetic events and private Chrome only. Synthetic paste validates routing/default-prevention; it does not claim trusted OS clipboard integration or native-device verification.
Harness limitation: importing full app widget dependencies into Flutter's Chrome test runner collides with SDK `host.dart.js` naming and hangs at loading. That attempt was interrupted and is not counted as passing. Browser bridge tests and a release-mode full app fixture avoid that test-server issue. No real chats or device clipboard were used. Work preserved for pipeline continuation; no commit, deployment or shared-service restart performed here.
Manager review: an accepted asynchronous file paste belongs to the original chat,
including when quick-switch makes it inactive while bytes decode. Listener
callbacks capture composer identity so decoded files/errors cannot attach to a
replacement composer that reuses the State; changing composer rebinds the listener.
Regressions cover both retained inactive ownership and stale-completion rejection.
Retained-workspace follow-up: after Back from a folded wide workspace,
Offstage keeps composers mounted. Pane ownership alone did not make paste
eligible: `ChatScreen` now additionally requires workspace visibility. Wide
visible conversations remain eligible; hidden retained panes leave both text
and file paste to the current destination.
Full-app regression starts wide, selects a chat, folds, returns to the list,
asserts the mounted hidden composer is ineligible, and sends native Ctrl+V:
zero clipboard reads occur and retapping Chats restores the unchanged draft.
Five application tests passed (`/tmp/memwatch/out.YeXKFV`); six existing native
paste-routing tests passed in the preceding combined runs. Analyzer clean
(`flutter-analyze.Jp8Rwp`). Full-app browser evidence
`/tmp/review/hidden-chat-paste-fixed` verifies hidden text/file events are not
prevented and the original draft remains on retap; both PNGs were inspected.
Script: `/tmp/hidden-chat-paste-capture.json`. No native device or server work.