Skip to content
4 changes: 4 additions & 0 deletions EGOTextView/EGOTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ extern NSString * const EGOTextAttachmentPlaceholderString;

- (void)egoTextView:(EGOTextView*)textView didSelectURL:(NSURL*)URL;

- (void)egoTextViewTouched:(EGOTextView*)textView;

@end

@protocol EGOTextAttachmentCell <NSObject>
Expand Down Expand Up @@ -79,6 +81,7 @@ extern NSString * const EGOTextAttachmentPlaceholderString;
BOOL _delegateRespondsToDidChange;
BOOL _delegateRespondsToDidChangeSelection;
BOOL _delegateRespondsToDidSelectURL;
BOOL _delegateRespondsToTouched;

NSAttributedString *_attributedString;
UIFont *_font;
Expand Down Expand Up @@ -121,5 +124,6 @@ extern NSString * const EGOTextAttachmentPlaceholderString;
@property(nonatomic) NSRange markedRange;

- (BOOL)hasText;
- (void)tap:(UITapGestureRecognizer*)gesture;

@end
71 changes: 52 additions & 19 deletions EGOTextView/EGOTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ - (void)setDelegate:(id<EGOTextViewDelegate>)aDelegate {
_delegateRespondsToDidChange = [delegate respondsToSelector:@selector(egoTextViewDidChange:)];
_delegateRespondsToDidChangeSelection = [delegate respondsToSelector:@selector(egoTextViewDidChangeSelection:)];
_delegateRespondsToDidSelectURL = [delegate respondsToSelector:@selector(egoTextView:didSelectURL:)];
_delegateRespondsToTouched = [delegate respondsToSelector:@selector(egoTextViewTouched:)];

}

Expand Down Expand Up @@ -969,6 +970,9 @@ - (void)selectionChanged {
[_textContentView setNeedsDisplay];
}

if(_delegateRespondsToDidChangeSelection) {
[self.delegate egoTextViewDidChangeSelection:self];
}
}

- (NSRange)markedRange {
Expand Down Expand Up @@ -1419,10 +1423,11 @@ - (void)insertText:(NSString *)text {

[newString release];

self.attributedString = _mutableAttributedString;
self.markedRange = markedTextRange;
self.selectedRange = selectedNSRange;

_selectedRange = selectedNSRange;
self.attributedString = _mutableAttributedString;
[self selectionChanged];

if (text.length > 1 || ([text isEqualToString:@" "] || [text isEqualToString:@"\n"])) {
[self checkSpellingForRange:[self characterRangeAtIndex:self.selectedRange.location-1]];
[self checkLinksForRange:NSMakeRange(0, self.attributedString.length)];
Expand Down Expand Up @@ -1484,9 +1489,14 @@ - (void)deleteBackward {

}

self.attributedString = _mutableAttributedString;
self.markedRange = markedTextRange;
self.selectedRange = selectedNSRange;
if(selectedNSRange.location > _mutableAttributedString.length) {
selectedNSRange.location = _mutableAttributedString.length;
selectedNSRange.length = 0;
}
_selectedRange = selectedNSRange;
self.attributedString = _mutableAttributedString;
[self selectionChanged];

}

Expand Down Expand Up @@ -1692,6 +1702,10 @@ - (EGOTextWindow*)egoTextWindow {
}

- (void)longPress:(UILongPressGestureRecognizer*)gesture {
if(_delegateRespondsToTouched) {
[self.delegate egoTextViewTouched:self];
}


if (gesture.state==UIGestureRecognizerStateBegan || gesture.state == UIGestureRecognizerStateChanged) {

Expand Down Expand Up @@ -1764,7 +1778,7 @@ - (void)longPress:(UILongPressGestureRecognizer*)gesture {
} else {

CGPoint location = [gesture locationInView:_textWindow];
CGRect rect = CGRectMake(location.x, location.y, _caretView.bounds.size.width, _caretView.bounds.size.height);
CGRect rect = CGRectMake(location.x + self.frame.origin.x, location.y - self.frame.origin.y, _caretView.bounds.size.width, _caretView.bounds.size.height);

self.selectedRange = NSMakeRange(index, 0);

Expand Down Expand Up @@ -1801,6 +1815,10 @@ - (void)longPress:(UILongPressGestureRecognizer*)gesture {
}

- (void)doubleTap:(UITapGestureRecognizer*)gesture {
if(_delegateRespondsToTouched) {
[self.delegate egoTextViewTouched:self];
}


[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showMenu) object:nil];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showCorrectionMenu) object:nil];
Expand All @@ -1821,7 +1839,10 @@ - (void)doubleTap:(UITapGestureRecognizer*)gesture {
}

- (void)tap:(UITapGestureRecognizer*)gesture {

if(_delegateRespondsToTouched) {
[self.delegate egoTextViewTouched:self];
}

if (_editable && ![self isFirstResponder]) {
[self becomeFirstResponder];
return;
Expand All @@ -1835,7 +1856,12 @@ - (void)tap:(UITapGestureRecognizer*)gesture {
self.selectedRange = NSMakeRange(_selectedRange.location, 0);
}

NSInteger index = [self closestWhiteSpaceIndexToPoint:[gesture locationInView:self]];
NSInteger index;
if(gesture) {
index = [self closestWhiteSpaceIndexToPoint:[gesture locationInView:self]];
} else {
index = 0;
}

if (_delegateRespondsToDidSelectURL && !_editing) {
if ([self selectedLinkAtIndex:index]) {
Expand All @@ -1850,13 +1876,13 @@ - (void)tap:(UITapGestureRecognizer*)gesture {

} else {

if (index==self.selectedRange.location) {
[self performSelector:@selector(showMenu) withObject:nil afterDelay:0.35f];
} else {
if (_editing) {
[self performSelector:@selector(showCorrectionMenu) withObject:nil afterDelay:0.35f];
}
}
// if (index==self.selectedRange.location) {
// [self performSelector:@selector(showMenu) withObject:nil afterDelay:0.35f];
// } else {
// if (_editing) {
// [self performSelector:@selector(showCorrectionMenu) withObject:nil afterDelay:0.35f];
// }
// }

}

Expand All @@ -1869,6 +1895,13 @@ - (void)tap:(UITapGestureRecognizer*)gesture {

}

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if(_delegateRespondsToTouched) {
[self.delegate egoTextViewTouched:self];
}
[super touchesBegan:touches withEvent:event];
}


/////////////////////////////////////////////////////////////////////////////
// MARK: -
Expand Down Expand Up @@ -2507,8 +2540,8 @@ - (void)showFromView:(UIView*)view rect:(CGRect)rect {
}

CGRect frame = _view.frame;
frame.origin.x = floorf(pos.x - (_view.bounds.size.width/2));
frame.origin.y = floorf(pos.y - _view.bounds.size.height);
frame.origin.x = floorf(pos.x - (_view.bounds.size.width/2) - view.superview.frame.origin.x);
frame.origin.y = floorf(pos.y - _view.bounds.size.height + view.superview.frame.origin.y);

if (_type==EGOWindowMagnify) {

Expand Down Expand Up @@ -2643,8 +2676,8 @@ - (void)renderWithContentView:(UIView*)view fromRect:(CGRect)rect {
if (_showing && _view!=nil) {

CGRect frame = _view.frame;
frame.origin.x = floorf((pos.x - (_view.bounds.size.width/2)) + (rect.size.width/2));
frame.origin.y = floorf(pos.y - _view.bounds.size.height);
frame.origin.x = floorf((pos.x - (_view.bounds.size.width/2)) + (rect.size.width/2) - view.superview.frame.origin.x);
frame.origin.y = floorf(pos.y - _view.bounds.size.height + view.superview.frame.origin.y);

if (_type==EGOWindowMagnify) {
frame.origin.y = MAX(0.0f, frame.origin.y);
Expand Down
8 changes: 8 additions & 0 deletions EGOTextView_Demo/EGOTextView_DemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ - (void)egoTextViewDidChange:(EGOTextView *)textView {

}

- (void)egoTextViewDidChangeSelection:(EGOTextView*)textView {
NSLog(@"%s", __PRETTY_FUNCTION__);
}

- (void)egoTextViewTouched:(EGOTextView*)textView {
NSLog(@"%s", __PRETTY_FUNCTION__);
}

- (void)egoTextView:(EGOTextView*)textView didSelectURL:(NSURL *)URL {

}
Expand Down