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:
2026-11-23 22:38:09 +00:00
parent cbc06b2f13
commit 4fe16375d9
3 changed files with 105 additions and 50 deletions
@@ -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;