Allow images to be pasted from Safari rather than their URL.

Use correct type.
This commit is contained in:
Doug
2021-10-18 11:52:31 +01:00
parent 2e0124b821
commit 22ee3d03ed
3 changed files with 40 additions and 2 deletions

View File

@@ -16,8 +16,14 @@
import GrowingTextView
@objc protocol RoomInputToolbarTextViewDelegate: AnyObject {
func textView(_ textView: RoomInputToolbarTextView, didReceivePasteForMediaFromSender sender: Any?)
}
class RoomInputToolbarTextView: GrowingTextView {
@objc weak var toolbarDelegate: RoomInputToolbarTextViewDelegate?
override var keyCommands: [UIKeyCommand]? {
return [UIKeyCommand(input: "\r", modifierFlags: [], action: #selector(keyCommandSelector(_:)))]
}
@@ -28,5 +34,19 @@ class RoomInputToolbarTextView: GrowingTextView {
}
delegate.onTouchUp(inside: delegate.rightInputToolbarButton)
}
}
/// Overrides paste to handle images pasted from Safari, passing them up to the input toolbar.
/// This is required as the pasteboard contains both the image and the image's URL, with the
/// default implementation choosing to paste the URL and completely ignore the image data.
override func paste(_ sender: Any?) {
let pasteboard = MXKPasteboardManager.shared.pasteboard
let types = pasteboard.types.map { UTI(rawValue: $0) }
if types.contains(where: { $0.conforms(to: .image) }) {
toolbarDelegate?.textView(self, didReceivePasteForMediaFromSender: sender)
} else {
super.paste(sender)
}
}
}