add file/image paste to the Claude composer via native clipboard
Flutter's clipboard is text-only and tmux/send-keys carry text only, so a pasted file or image must reach Claude as an @path reference (per the T-134 spike). A native clide/clipboard MethodChannel reads the non-text clipboard: GTK (gtk_clipboard_wait_for_image/uris) on Linux, NSPasteboard on macOS. The composer overrides PasteTextIntent — Ctrl/Cmd+V resolves a file path or writes a clipboard image to a cache dir, inserts the @path, and falls back to plain-text paste otherwise. No new package dependency. macOS handler is written but unverified on this Linux box — needs a build on a Mac. Linux path builds and is covered by tests. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -64,5 +64,35 @@ class AppDelegate: FlutterAppDelegate {
|
||||
result(FlutterMethodNotImplemented)
|
||||
}
|
||||
}
|
||||
|
||||
// T-138: native clipboard image/file reads. Flutter's built-in
|
||||
// clipboard is text-only; the composer turns a pasted file or image
|
||||
// into a Claude `@path` reference, which needs the non-text pasteboard
|
||||
// contents read here.
|
||||
let clipboardChannel = FlutterMethodChannel(
|
||||
name: "clide/clipboard",
|
||||
binaryMessenger: flutterVC.engine.binaryMessenger)
|
||||
|
||||
clipboardChannel.setMethodCallHandler { (call, result) in
|
||||
let pasteboard = NSPasteboard.general
|
||||
switch call.method {
|
||||
case "readImage":
|
||||
if let image = NSImage(pasteboard: pasteboard),
|
||||
let tiff = image.tiffRepresentation,
|
||||
let rep = NSBitmapImageRep(data: tiff),
|
||||
let png = rep.representation(using: .png, properties: [:]) {
|
||||
result(FlutterStandardTypedData(bytes: png))
|
||||
} else {
|
||||
result(nil)
|
||||
}
|
||||
case "readFiles":
|
||||
let urls = pasteboard.readObjects(
|
||||
forClasses: [NSURL.self],
|
||||
options: [.urlReadingFileURLsOnly: true]) as? [URL] ?? []
|
||||
result(urls.map { $0.path })
|
||||
default:
|
||||
result(FlutterMethodNotImplemented)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user