Skip to content

Commit

Permalink
Update tokenizer.
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyin1986 committed May 1, 2020
1 parent 3b63435 commit 3f20a98
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions YYText/YYTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1071,10 +1071,10 @@ - (YYTextRange *)_getClosestTokenRangeAtPosition:(YYTextPosition *)position {
position = [self _correctedTextPosition:position];
if (!position) return nil;
YYTextRange *range = nil;
if (_tokenizer) {
range = (id)[_tokenizer rangeEnclosingPosition:position withGranularity:UITextGranularityWord inDirection:UITextStorageDirectionForward];
if (self.tokenizer) {
range = (id)[self.tokenizer rangeEnclosingPosition:position withGranularity:UITextGranularityWord inDirection:UITextStorageDirectionForward];
if (range.asRange.length == 0) {
range = (id)[_tokenizer rangeEnclosingPosition:position withGranularity:UITextGranularityWord inDirection:UITextStorageDirectionBackward];
range = (id)[self.tokenizer rangeEnclosingPosition:position withGranularity:UITextGranularityWord inDirection:UITextStorageDirectionBackward];
}
}

Expand Down Expand Up @@ -1108,9 +1108,9 @@ - (YYTextRange *)_getClosestTokenRangeAtPoint:(CGPoint)point {
YYTextRange *touchRange = [_innerLayout closestTextRangeAtPoint:point];
touchRange = [self _correctedTextRange:touchRange];

if (_tokenizer && touchRange) {
YYTextRange *encEnd = (id)[_tokenizer rangeEnclosingPosition:touchRange.end withGranularity:UITextGranularityWord inDirection:UITextStorageDirectionBackward];
YYTextRange *encStart = (id)[_tokenizer rangeEnclosingPosition:touchRange.start withGranularity:UITextGranularityWord inDirection:UITextStorageDirectionForward];
if (self.tokenizer && touchRange) {
YYTextRange *encEnd = (id)[self.tokenizer rangeEnclosingPosition:touchRange.end withGranularity:UITextGranularityWord inDirection:UITextStorageDirectionBackward];
YYTextRange *encStart = (id)[self.tokenizer rangeEnclosingPosition:touchRange.start withGranularity:UITextGranularityWord inDirection:UITextStorageDirectionForward];
if (encEnd && encStart) {
NSArray *arr = [@[encEnd.start, encEnd.end, encStart.start, encStart.end] sortedArrayUsingSelector:@selector(compare:)];
touchRange = [YYTextRange rangeWithStart:arr.firstObject end:arr.lastObject];
Expand Down

0 comments on commit 3f20a98

Please sign in to comment.