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:
@@ -98,12 +98,27 @@ Future<void> _readPasteboard(
|
||||
if (failures.isNotEmpty) return;
|
||||
try {
|
||||
final text = (await Clipboard.getData(Clipboard.kTextPlain))?.text;
|
||||
if (text != null && text.isNotEmpty) onText(text);
|
||||
if (text != null && text.isNotEmpty) {
|
||||
onText(text);
|
||||
return;
|
||||
}
|
||||
} catch (_) {
|
||||
onError('Could not read clipboard text.');
|
||||
return;
|
||||
}
|
||||
// Neither files, an image nor text: say what the clipboard held rather
|
||||
// than letting the paste do nothing.
|
||||
final types = [
|
||||
for (final type in (reply?['types'] as List<Object?>?) ?? const []) '$type',
|
||||
];
|
||||
if (reply != null) onError(chatNothingToPasteMessage(types));
|
||||
}
|
||||
|
||||
/// The error for a paste whose clipboard held nothing the composer can take.
|
||||
String chatNothingToPasteMessage(List<String> types) => types.isEmpty
|
||||
? 'Nothing to paste: the clipboard is empty.'
|
||||
: 'Nothing to paste: the clipboard holds ${types.take(6).join(', ')}.';
|
||||
|
||||
/// Whether [platform] has a Runner that answers [chatClipboardFilesChannel].
|
||||
bool chatHostReadsClipboardFiles(TargetPlatform platform) =>
|
||||
!kIsWeb && platform == TargetPlatform.macOS;
|
||||
|
||||
Reference in New Issue
Block a user