From 75d4f47c24dbaf1ddf25be6cf7c636d5162f1425 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sat, 25 May 2019 15:12:42 +0200 Subject: [PATCH] ASEditableTextNode: added shouldCopy callback --- Source/ASEditableTextNode.h | 1 + Source/ASEditableTextNode.mm | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/Source/ASEditableTextNode.h b/Source/ASEditableTextNode.h index e15a288515..030084cfb1 100644 --- a/Source/ASEditableTextNode.h +++ b/Source/ASEditableTextNode.h @@ -211,6 +211,7 @@ NS_ASSUME_NONNULL_BEGIN */ - (void)editableTextNodeDidFinishEditing:(ASEditableTextNode *)editableTextNode; +- (BOOL)editableTextNodeShouldCopy:(ASEditableTextNode *)editableTextNode; - (BOOL)editableTextNodeShouldPaste:(ASEditableTextNode *)editableTextNode; - (ASEditableTextNodeTargetForAction * _Nullable)editableTextNodeTargetForAction:(SEL)action; - (BOOL)editableTextNodeShouldReturn:(ASEditableTextNode *)editableTextNode; diff --git a/Source/ASEditableTextNode.mm b/Source/ASEditableTextNode.mm index d2ca7ef6a3..c1f4cd93ea 100644 --- a/Source/ASEditableTextNode.mm +++ b/Source/ASEditableTextNode.mm @@ -86,6 +86,7 @@ BOOL _initializedPrimaryInputLanguage; } +@property (nonatomic, copy) bool (^shouldCopy)(); @property (nonatomic, copy) bool (^shouldPaste)(); @property (nonatomic, copy) ASEditableTextNodeTargetForAction *(^targetForActionImpl)(SEL); @property (nonatomic, copy) bool (^shouldReturn)(); @@ -162,6 +163,12 @@ } return [super targetForAction:action withSender:sender]; } + +- (void)copy:(id)sender { + if (_shouldCopy == nil || _shouldCopy()) { + [super copy:sender]; + } +} - (void)paste:(id)sender { @@ -336,6 +343,15 @@ ASPanningOverriddenUITextView *textView = [[ASPanningOverriddenUITextView alloc] initWithFrame:CGRectZero textContainer:_textKitComponents.textContainer]; textView.initialPrimaryLanguage = _initialPrimaryLanguage; __weak ASEditableTextNode *weakSelf = self; + textView.shouldCopy = ^bool{ + __strong ASEditableTextNode *strongSelf = weakSelf; + if (strongSelf != nil) { + if ([strongSelf->_delegate respondsToSelector:@selector(editableTextNodeShouldCopy:)]) { + return [strongSelf->_delegate editableTextNodeShouldCopy:self]; + } + } + return true; + }; textView.shouldPaste = ^bool{ __strong ASEditableTextNode *strongSelf = weakSelf; if (strongSelf != nil) {