Let the composer being typed in take pasted files; free Cmd+V on macOS

A composer outside the active pane (a floating chat window, a side pane)
refused file pastes even while focused, so the field's own text paste
ran instead: a Finder copy pasted its file name and an image nothing.
The focused composer now always takes the paste.

On macOS the Edit > Paste menu item owned Cmd+V and sent paste: to the
native text view, which pastes plain text only and never lets the key
reach Flutter. The item keeps working from the menu but no longer claims
the shortcut, so Cmd+V reaches the composer's file paste.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 00:06:06 +00:00
parent 4fe16375d9
commit 50c89976fa
3 changed files with 35 additions and 2 deletions
@@ -318,7 +318,10 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
/// default behaviour, so an inactive pane is never allowed to swallow it.
bool _canAcceptPaste() =>
mounted &&
(widget.ownsPasteWhenFocused && _focus.hasFocus ||
// The composer the operator is typing in always takes the paste (a
// floating window's or a side pane's too); otherwise the active pane
// does, unless another composer has the keyboard.
(_focus.hasFocus ||
widget.pasteTarget &&
!ChatComposerPasteFocus.otherOwnerHasFocus(_focus)) &&
_composerIsCurrent() &&
+1 -1
View File
@@ -91,7 +91,7 @@
<action selector="copy:" target="-1" id="G1f-GL-Joy"/>
</connections>
</menuItem>
<menuItem title="Paste" keyEquivalent="v" id="gVA-U4-sdL">
<menuItem title="Paste" id="gVA-U4-sdL">
<connections>
<action selector="paste:" target="-1" id="UvS-8e-Qdg"/>
</connections>
@@ -130,6 +130,36 @@ void main() {
}, variant: _macOS);
}
testWidgets('a focused composer outside the active pane takes the paste', (
tester,
) async {
// A floating chat window's or a side pane's composer is not the paste
// target, but the operator typing in it means the paste is for it.
pasteboard = {
'files': [
{
'name': 'notes.txt',
'mime': 'text/plain',
'bytes': Uint8List.fromList([104, 105]),
},
],
'errors': const [],
};
await tester.pumpWidget(
materialHost(
ChatComposerBar(composer: composer, running: false, pasteTarget: false),
),
);
await tester.pumpAndSettle();
await tester.showKeyboard(_field);
await tester.pump();
await paste(tester);
expect(fileReads, 1);
expect(find.text('notes.txt'), findsOneWidget);
expect(composer.draft, isEmpty);
await done(tester);
}, variant: _macOS);
testWidgets('a paste with nothing usable says what the clipboard held', (
tester,
) async {