Skip to content

Commit

Permalink
Remove dataSource, add loseSelection delegate.
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyin1986 committed Apr 21, 2020
1 parent d5adace commit 8ac817e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
12 changes: 1 addition & 11 deletions YYText/YYTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@

NS_ASSUME_NONNULL_BEGIN

@protocol YYTextViewDataSource <NSObject>
@optional
- (id<UITextInputTokenizer>)customizeTokenizer;
@end

/**
The YYTextViewDelegate protocol defines a set of optional methods you can use
to receive editing-related messages for YYTextView objects.
Expand All @@ -51,6 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)textView:(YYTextView *)textView shouldLongPressHighlight:(YYTextHighlight *)highlight inRange:(NSRange)characterRange;
- (void)textView:(YYTextView *)textView didLongPressHighlight:(YYTextHighlight *)highlight inRange:(NSRange)characterRange rect:(CGRect)rect;
- (void)textView:(YYTextView *)textView didTapAndSelectTextInRange:(NSRange)range;
- (void)textViewDidLoseSelection:(YYTextView *)textView;
@end


Expand All @@ -74,12 +70,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
@interface YYTextView : UIScrollView <UITextInput>

#pragma mark - Accessing the DataSource
///=============================================================================
/// @name Accessing the Delegate
///=============================================================================
@property (nullable, nonatomic, weak) id<YYTextViewDataSource> dataSource;

#pragma mark - Accessing the Delegate
///=============================================================================
/// @name Accessing the Delegate
Expand Down
13 changes: 6 additions & 7 deletions YYText/YYTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,12 @@ - (void)_updateSelectionView {
[allRects enumerateObjectsUsingBlock:^(YYTextSelectionRect *rect, NSUInteger idx, BOOL *stop) {
rect.rect = [self _convertRectFromLayout:rect.rect];
}];

NSInteger count = [allRects count];
if (count <= 0 && [_outerDelegate respondsToSelector:@selector(textViewDidLoseSelection:)]) {
[_outerDelegate textViewDidLoseSelection:self];
}

_selectionView.selectionRects = allRects;
if (!_state.firstShowDot && containsDot) {
_state.firstShowDot = YES;
Expand Down Expand Up @@ -1913,13 +1919,6 @@ - (void)_initTextView {
_markedTextRange = nil;
_markedTextStyle = nil;

if ([_dataSource respondsToSelector:@selector(customizeTokenizer)]) {
id tokenizer = [_dataSource customizeTokenizer];
if (tokenizer) {
_tokenizer = tokenizer;
}
}

if (!_tokenizer) {
_tokenizer = [[UITextInputStringTokenizer alloc] initWithTextInput:self];
}
Expand Down

0 comments on commit 8ac817e

Please sign in to comment.