mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-29 07:42:40 +00:00
Allow images to be pasted from Safari rather than their URL.
Use correct type.
This commit is contained in:
parent
1126e5f9a6
commit
98be850786
3 changed files with 40 additions and 2 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ const NSTimeInterval kActionMenuContentAlphaAnimationDuration = .2;
|
|||
const NSTimeInterval kActionMenuComposerHeightAnimationDuration = .3;
|
||||
const CGFloat kComposerContainerTrailingPadding = 12;
|
||||
|
||||
@interface RoomInputToolbarView() <GrowingTextViewDelegate>
|
||||
@interface RoomInputToolbarView() <GrowingTextViewDelegate, RoomInputToolbarTextViewDelegate>
|
||||
{
|
||||
// The intermediate action sheet
|
||||
UIAlertController *actionSheet;
|
||||
|
@ -83,6 +83,8 @@ const CGFloat kComposerContainerTrailingPadding = 12;
|
|||
self.isEncryptionEnabled = _isEncryptionEnabled;
|
||||
|
||||
[self updateUIWithTextMessage:nil animated:NO];
|
||||
|
||||
self.textView.toolbarDelegate = self;
|
||||
}
|
||||
|
||||
- (void)setVoiceMessageToolbarView:(UIView *)voiceMessageToolbarView
|
||||
|
@ -382,6 +384,16 @@ const CGFloat kComposerContainerTrailingPadding = 12;
|
|||
[super onTouchUpInside:button];
|
||||
}
|
||||
|
||||
- (BOOL)becomeFirstResponder
|
||||
{
|
||||
return [self.textView becomeFirstResponder];
|
||||
}
|
||||
|
||||
- (void)dismissKeyboard
|
||||
{
|
||||
[self.textView resignFirstResponder];
|
||||
}
|
||||
|
||||
- (void)destroy
|
||||
{
|
||||
if (actionSheet)
|
||||
|
@ -455,6 +467,11 @@ const CGFloat kComposerContainerTrailingPadding = 12;
|
|||
[super paste:sender];
|
||||
}
|
||||
|
||||
- (void)textView:(GrowingTextView *)textView didReceivePasteForMediaFromSender:(id)sender
|
||||
{
|
||||
[self paste:sender];
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
- (void)updateUIWithTextMessage:(NSString *)textMessage animated:(BOOL)animated
|
||||
|
|
1
changelog.d/2076.bugfix
Normal file
1
changelog.d/2076.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Message Composer: Pasting images from Safari now pastes the image and not its URL.
|
Loading…
Reference in a new issue