From 9f24889b4cf4ea320a628f679b54288372f32c9f Mon Sep 17 00:00:00 2001 From: "James N. Sears" Date: Fri, 28 Dec 2012 06:45:38 -0500 Subject: [PATCH 01/12] Fixes to handle non-zero frame origin --- EGOTextView/EGOTextView.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/EGOTextView/EGOTextView.m b/EGOTextView/EGOTextView.m index cb5b4ef..9f27359 100644 --- a/EGOTextView/EGOTextView.m +++ b/EGOTextView/EGOTextView.m @@ -1764,7 +1764,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); @@ -2507,8 +2507,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) { @@ -2643,8 +2643,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); From 6c2af71b1130533e3841605987a9daa096065d48 Mon Sep 17 00:00:00 2001 From: "James N. Sears" Date: Fri, 28 Dec 2012 10:21:42 -0500 Subject: [PATCH 02/12] Fix selection position on change --- EGOTextView/EGOTextView.m | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/EGOTextView/EGOTextView.m b/EGOTextView/EGOTextView.m index 9f27359..e3b3ba3 100644 --- a/EGOTextView/EGOTextView.m +++ b/EGOTextView/EGOTextView.m @@ -1419,10 +1419,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)]; @@ -1484,9 +1485,10 @@ - (void)deleteBackward { } - self.attributedString = _mutableAttributedString; self.markedRange = markedTextRange; - self.selectedRange = selectedNSRange; + _selectedRange = selectedNSRange; + self.attributedString = _mutableAttributedString; + [self selectionChanged]; } From 32a65847c7ee613e17554e2c7bfe37f87979b274 Mon Sep 17 00:00:00 2001 From: "James N. Sears" Date: Sun, 30 Dec 2012 06:57:32 -0500 Subject: [PATCH 03/12] Catch mistaken range calculation on correction range delete --- EGOTextView/EGOTextView.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/EGOTextView/EGOTextView.m b/EGOTextView/EGOTextView.m index e3b3ba3..e691b49 100644 --- a/EGOTextView/EGOTextView.m +++ b/EGOTextView/EGOTextView.m @@ -1486,6 +1486,10 @@ - (void)deleteBackward { } self.markedRange = markedTextRange; + if(selectedNSRange.location > _mutableAttributedString.length) { + selectedNSRange.location = _mutableAttributedString.length; + selectedNSRange.length = 0; + } _selectedRange = selectedNSRange; self.attributedString = _mutableAttributedString; [self selectionChanged]; From 550f74dc89abd43add792a32d3f5aebfea799be5 Mon Sep 17 00:00:00 2001 From: "James N. Sears" Date: Mon, 31 Dec 2012 19:04:12 -0500 Subject: [PATCH 04/12] didChangeSelection fixed --- EGOTextView/EGOTextView.m | 3 +++ EGOTextView_Demo/EGOTextView_DemoViewController.m | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/EGOTextView/EGOTextView.m b/EGOTextView/EGOTextView.m index e691b49..a0681fd 100644 --- a/EGOTextView/EGOTextView.m +++ b/EGOTextView/EGOTextView.m @@ -969,6 +969,9 @@ - (void)selectionChanged { [_textContentView setNeedsDisplay]; } + if(_delegateRespondsToDidChangeSelection) { + [self.delegate egoTextViewDidChangeSelection:self]; + } } - (NSRange)markedRange { diff --git a/EGOTextView_Demo/EGOTextView_DemoViewController.m b/EGOTextView_Demo/EGOTextView_DemoViewController.m index 584ad91..1cf7aed 100644 --- a/EGOTextView_Demo/EGOTextView_DemoViewController.m +++ b/EGOTextView_Demo/EGOTextView_DemoViewController.m @@ -103,6 +103,10 @@ - (void)egoTextViewDidChange:(EGOTextView *)textView { } +- (void)egoTextViewDidChangeSelection:(EGOTextView*)textView { + NSLog(@"%s", __PRETTY_FUNCTION__); +} + - (void)egoTextView:(EGOTextView*)textView didSelectURL:(NSURL *)URL { } From c97437284d9c96151f5b351051162de1f5c39e06 Mon Sep 17 00:00:00 2001 From: "James N. Sears" Date: Mon, 31 Dec 2012 19:14:54 -0500 Subject: [PATCH 05/12] Touched event --- EGOTextView/EGOTextView.h | 3 +++ EGOTextView/EGOTextView.m | 21 ++++++++++++++++++- .../EGOTextView_DemoViewController.m | 4 ++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/EGOTextView/EGOTextView.h b/EGOTextView/EGOTextView.h index 67974aa..6a50996 100644 --- a/EGOTextView/EGOTextView.h +++ b/EGOTextView/EGOTextView.h @@ -47,6 +47,8 @@ extern NSString * const EGOTextAttachmentPlaceholderString; - (void)egoTextView:(EGOTextView*)textView didSelectURL:(NSURL*)URL; +- (void)egoTextViewTouched:(EGOTextView*)textView; + @end @protocol EGOTextAttachmentCell @@ -79,6 +81,7 @@ extern NSString * const EGOTextAttachmentPlaceholderString; BOOL _delegateRespondsToDidChange; BOOL _delegateRespondsToDidChangeSelection; BOOL _delegateRespondsToDidSelectURL; + BOOL _delegateRespondsToTouched; NSAttributedString *_attributedString; UIFont *_font; diff --git a/EGOTextView/EGOTextView.m b/EGOTextView/EGOTextView.m index a0681fd..9dc0b59 100644 --- a/EGOTextView/EGOTextView.m +++ b/EGOTextView/EGOTextView.m @@ -413,6 +413,7 @@ - (void)setDelegate:(id)aDelegate { _delegateRespondsToDidChange = [delegate respondsToSelector:@selector(egoTextViewDidChange:)]; _delegateRespondsToDidChangeSelection = [delegate respondsToSelector:@selector(egoTextViewDidChangeSelection:)]; _delegateRespondsToDidSelectURL = [delegate respondsToSelector:@selector(egoTextView:didSelectURL:)]; + _delegateRespondsToTouched = [delegate respondsToSelector:@selector(egoTextViewTouched:)]; } @@ -1701,6 +1702,10 @@ - (EGOTextWindow*)egoTextWindow { } - (void)longPress:(UILongPressGestureRecognizer*)gesture { + if(_delegateRespondsToTouched) { + [self.delegate egoTextViewTouched:self]; + } + if (gesture.state==UIGestureRecognizerStateBegan || gesture.state == UIGestureRecognizerStateChanged) { @@ -1810,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]; @@ -1830,7 +1839,10 @@ - (void)doubleTap:(UITapGestureRecognizer*)gesture { } - (void)tap:(UITapGestureRecognizer*)gesture { - + if(_delegateRespondsToTouched) { + [self.delegate egoTextViewTouched:self]; + } + if (_editable && ![self isFirstResponder]) { [self becomeFirstResponder]; return; @@ -1878,6 +1890,13 @@ - (void)tap:(UITapGestureRecognizer*)gesture { } +-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { + if(_delegateRespondsToTouched) { + [self.delegate egoTextViewTouched:self]; + } + [super touchesBegan:touches withEvent:event]; +} + ///////////////////////////////////////////////////////////////////////////// // MARK: - diff --git a/EGOTextView_Demo/EGOTextView_DemoViewController.m b/EGOTextView_Demo/EGOTextView_DemoViewController.m index 1cf7aed..7b37880 100644 --- a/EGOTextView_Demo/EGOTextView_DemoViewController.m +++ b/EGOTextView_Demo/EGOTextView_DemoViewController.m @@ -107,6 +107,10 @@ - (void)egoTextViewDidChangeSelection:(EGOTextView*)textView { NSLog(@"%s", __PRETTY_FUNCTION__); } +- (void)egoTextViewTouched:(EGOTextView*)textView { + NSLog(@"%s", __PRETTY_FUNCTION__); +} + - (void)egoTextView:(EGOTextView*)textView didSelectURL:(NSURL *)URL { } From a690d4c893e0039c8cfae885e5aac96bf6580895 Mon Sep 17 00:00:00 2001 From: "James N. Sears" Date: Mon, 14 Jan 2013 17:32:47 -0500 Subject: [PATCH 06/12] Exposing tap for autocap hack --- EGOTextView/EGOTextView.h | 1 + 1 file changed, 1 insertion(+) diff --git a/EGOTextView/EGOTextView.h b/EGOTextView/EGOTextView.h index 6a50996..b933402 100644 --- a/EGOTextView/EGOTextView.h +++ b/EGOTextView/EGOTextView.h @@ -124,5 +124,6 @@ extern NSString * const EGOTextAttachmentPlaceholderString; @property(nonatomic) NSRange markedRange; - (BOOL)hasText; +- (void)tap:(UITapGestureRecognizer*)gesture; @end \ No newline at end of file From c7c5179de66875dc0c3acb074d1dae5a343c740d Mon Sep 17 00:00:00 2001 From: "James N. Sears" Date: Mon, 14 Jan 2013 17:44:57 -0500 Subject: [PATCH 07/12] Exposing tap for autocap hack --- EGOTextView/EGOTextView.m | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/EGOTextView/EGOTextView.m b/EGOTextView/EGOTextView.m index 9dc0b59..bab8941 100644 --- a/EGOTextView/EGOTextView.m +++ b/EGOTextView/EGOTextView.m @@ -1871,13 +1871,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]; +// } +// } } From 36f31e7848358f8af506b82acd55562fa18256ac Mon Sep 17 00:00:00 2001 From: "James N. Sears" Date: Mon, 14 Jan 2013 17:47:54 -0500 Subject: [PATCH 08/12] Exposing tap for autocap hack --- EGOTextView/EGOTextView.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/EGOTextView/EGOTextView.m b/EGOTextView/EGOTextView.m index bab8941..861c473 100644 --- a/EGOTextView/EGOTextView.m +++ b/EGOTextView/EGOTextView.m @@ -1856,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]) { From bae4ca5921d8698e96f576fcb1b0722432b76346 Mon Sep 17 00:00:00 2001 From: "James N. Sears" Date: Mon, 14 Jan 2013 17:50:47 -0500 Subject: [PATCH 09/12] Exposing tap for autocap hack --- EGOTextView/EGOTextView.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/EGOTextView/EGOTextView.m b/EGOTextView/EGOTextView.m index 861c473..596c65f 100644 --- a/EGOTextView/EGOTextView.m +++ b/EGOTextView/EGOTextView.m @@ -1861,6 +1861,10 @@ - (void)tap:(UITapGestureRecognizer*)gesture { index = [self closestWhiteSpaceIndexToPoint:[gesture locationInView:self]]; } else { index = 0; + self.markedRange = NSMakeRange(0, 0); + self.selectedRange = NSMakeRange(index, 0); + return; + } if (_delegateRespondsToDidSelectURL && !_editing) { From 74ba6ca263a0bb789dd5d4a6ec9456040ab840ae Mon Sep 17 00:00:00 2001 From: "James N. Sears" Date: Mon, 14 Jan 2013 17:54:07 -0500 Subject: [PATCH 10/12] Exposing tap for autocap hack --- EGOTextView/EGOTextView.m | 4 ---- 1 file changed, 4 deletions(-) diff --git a/EGOTextView/EGOTextView.m b/EGOTextView/EGOTextView.m index 596c65f..861c473 100644 --- a/EGOTextView/EGOTextView.m +++ b/EGOTextView/EGOTextView.m @@ -1861,10 +1861,6 @@ - (void)tap:(UITapGestureRecognizer*)gesture { index = [self closestWhiteSpaceIndexToPoint:[gesture locationInView:self]]; } else { index = 0; - self.markedRange = NSMakeRange(0, 0); - self.selectedRange = NSMakeRange(index, 0); - return; - } if (_delegateRespondsToDidSelectURL && !_editing) { From 7c32afc9191a5c6696d75d3c742b7faf02066e82 Mon Sep 17 00:00:00 2001 From: "James N. Sears" Date: Mon, 14 Jan 2013 17:57:25 -0500 Subject: [PATCH 11/12] Exposing tap for autocap hack --- EGOTextView/EGOTextView.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/EGOTextView/EGOTextView.m b/EGOTextView/EGOTextView.m index 861c473..9eed0a0 100644 --- a/EGOTextView/EGOTextView.m +++ b/EGOTextView/EGOTextView.m @@ -1888,7 +1888,11 @@ - (void)tap:(UITapGestureRecognizer*)gesture { [self.inputDelegate selectionWillChange:self]; - self.markedRange = NSMakeRange(NSNotFound, 0); + if(gesture) { + self.markedRange = NSMakeRange(NSNotFound, 0); + } else { + self.markedRange = NSMakeRange(0, 0); + } self.selectedRange = NSMakeRange(index, 0); [self.inputDelegate selectionDidChange:self]; From 1f48622117459c61a8c2def8537dc2ec79237a52 Mon Sep 17 00:00:00 2001 From: "James N. Sears" Date: Mon, 14 Jan 2013 17:58:47 -0500 Subject: [PATCH 12/12] Exposing tap for autocap hack --- EGOTextView/EGOTextView.m | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/EGOTextView/EGOTextView.m b/EGOTextView/EGOTextView.m index 9eed0a0..861c473 100644 --- a/EGOTextView/EGOTextView.m +++ b/EGOTextView/EGOTextView.m @@ -1888,11 +1888,7 @@ - (void)tap:(UITapGestureRecognizer*)gesture { [self.inputDelegate selectionWillChange:self]; - if(gesture) { - self.markedRange = NSMakeRange(NSNotFound, 0); - } else { - self.markedRange = NSMakeRange(0, 0); - } + self.markedRange = NSMakeRange(NSNotFound, 0); self.selectedRange = NSMakeRange(index, 0); [self.inputDelegate selectionDidChange:self];