ASEditableTextNode: added shouldCopy callback

This commit is contained in:
Ilya Laktyushin 2019-05-25 15:12:42 +02:00
parent 16ce3e690a
commit 75d4f47c24
2 changed files with 17 additions and 0 deletions

View File

@ -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;

View File

@ -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) {