macOS paste: read more image and file kinds, never fail silently
The pasteboard reader now also takes any image AppKit can read (JPEG, HEIC, PDF and others, converted to PNG) and the legacy Finder filenames list. A paste with no files, no image and no text now shows which types the clipboard held instead of doing nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -19,6 +18,7 @@ void main() {
|
||||
late ChatComposerController composer;
|
||||
late Map<String, Object?> pasteboard;
|
||||
late int fileReads, textReads;
|
||||
String? clipboardText;
|
||||
|
||||
setUp(() {
|
||||
gateway = ComposerBarGateway();
|
||||
@@ -30,6 +30,7 @@ void main() {
|
||||
pasteboard = {'files': const [], 'errors': const []};
|
||||
fileReads = 0;
|
||||
textReads = 0;
|
||||
clipboardText = 'copied text';
|
||||
final messenger =
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
||||
messenger.setMockMethodCallHandler(chatClipboardFilesChannel, (call) async {
|
||||
@@ -40,7 +41,7 @@ void main() {
|
||||
messenger.setMockMethodCallHandler(SystemChannels.platform, (call) async {
|
||||
if (call.method == 'Clipboard.getData') {
|
||||
textReads++;
|
||||
return {'text': 'copied text'};
|
||||
return clipboardText == null ? null : {'text': clipboardText};
|
||||
}
|
||||
if (call.method == 'Clipboard.hasStrings') return {'value': true};
|
||||
return null;
|
||||
@@ -93,59 +94,81 @@ void main() {
|
||||
}, variant: _macOS);
|
||||
|
||||
for (final focused in [true, false]) {
|
||||
testWidgets(
|
||||
'Cmd+V attaches a Finder file and a screenshot '
|
||||
'(${focused ? 'focused' : 'unfocused'} composer)',
|
||||
(tester) async {
|
||||
pasteboard = {
|
||||
'files': [
|
||||
{
|
||||
'name': 'report.pdf',
|
||||
'mime': 'application/pdf',
|
||||
'bytes': Uint8List.fromList([1, 2]),
|
||||
},
|
||||
{
|
||||
'name': '',
|
||||
'mime': 'image/png',
|
||||
'bytes': Uint8List.fromList([3]),
|
||||
},
|
||||
],
|
||||
'errors': const [],
|
||||
};
|
||||
await mount(tester);
|
||||
if (focused) {
|
||||
await tester.showKeyboard(_field);
|
||||
} else {
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
}
|
||||
await tester.pump();
|
||||
await paste(tester);
|
||||
testWidgets('Cmd+V attaches a Finder file and a screenshot '
|
||||
'(${focused ? 'focused' : 'unfocused'} composer)', (tester) async {
|
||||
pasteboard = {
|
||||
'files': [
|
||||
{
|
||||
'name': 'report.pdf',
|
||||
'mime': 'application/pdf',
|
||||
'bytes': Uint8List.fromList([1, 2]),
|
||||
},
|
||||
{
|
||||
'name': '',
|
||||
'mime': 'image/png',
|
||||
'bytes': Uint8List.fromList([3]),
|
||||
},
|
||||
],
|
||||
'errors': const [],
|
||||
};
|
||||
await mount(tester);
|
||||
if (focused) {
|
||||
await tester.showKeyboard(_field);
|
||||
} else {
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
}
|
||||
await tester.pump();
|
||||
await paste(tester);
|
||||
|
||||
expect(fileReads, 1);
|
||||
expect(find.text('report.pdf'), findsOneWidget);
|
||||
expect(find.text('pasted-1.png'), findsOneWidget);
|
||||
// The pasteboard's file-name text is not pasted alongside the files.
|
||||
expect(textReads, 0);
|
||||
expect(composer.draft, isEmpty);
|
||||
await done(tester);
|
||||
},
|
||||
variant: _macOS,
|
||||
);
|
||||
expect(fileReads, 1);
|
||||
expect(find.text('report.pdf'), findsOneWidget);
|
||||
expect(find.text('pasted-1.png'), findsOneWidget);
|
||||
// The pasteboard's file-name text is not pasted alongside the files.
|
||||
expect(textReads, 0);
|
||||
expect(composer.draft, isEmpty);
|
||||
await done(tester);
|
||||
}, variant: _macOS);
|
||||
}
|
||||
|
||||
testWidgets('Cmd+V of plain text pastes it once into the focused composer', (
|
||||
testWidgets('a paste with nothing usable says what the clipboard held', (
|
||||
tester,
|
||||
) async {
|
||||
pasteboard = {
|
||||
'files': const [],
|
||||
'errors': const [],
|
||||
'types': ['com.example.private', 'public.url'],
|
||||
};
|
||||
clipboardText = null;
|
||||
await mount(tester);
|
||||
await tester.showKeyboard(_field);
|
||||
await tester.pump();
|
||||
await paste(tester);
|
||||
|
||||
expect(fileReads, 1);
|
||||
expect(textReads, 1);
|
||||
expect(composer.draft, 'copied text');
|
||||
expect(
|
||||
find.text(
|
||||
chatNothingToPasteMessage(['com.example.private', 'public.url']),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(composer.draft, isEmpty);
|
||||
await done(tester);
|
||||
}, variant: _macOS);
|
||||
|
||||
testWidgets(
|
||||
'Cmd+V of plain text pastes it once into the focused composer',
|
||||
(tester) async {
|
||||
await mount(tester);
|
||||
await tester.showKeyboard(_field);
|
||||
await paste(tester);
|
||||
|
||||
expect(fileReads, 1);
|
||||
expect(textReads, 1);
|
||||
expect(composer.draft, 'copied text');
|
||||
await done(tester);
|
||||
},
|
||||
variant: _macOS,
|
||||
);
|
||||
|
||||
testWidgets('an unreadable pasted file is reported, not dropped silently', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
Reference in New Issue
Block a user