Skip to content

Commit

Permalink
Merge pull request #5 from kareemk/fix-double-space
Browse files Browse the repository at this point in the history
Fix double space inserting a period. Thanks @kareemk!
  • Loading branch information
alexruperez committed Aug 4, 2014
2 parents 55f1aa3 + 348313e commit 53e4536
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Classes/ARAutocompleteTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@interface ARAutocompleteTextView ()

@property (nonatomic, strong) NSString *autocompleteString;
@property (nonatomic, assign) BOOL autocompleted;

@end

Expand Down Expand Up @@ -63,6 +64,7 @@ - (void)setupAutocompleteTextView
[self bringSubviewToFront:self.autocompleteLabel];

self.autocompleteString = @"";
self.autocompleted = NO;

self.ignoreCase = YES;

Expand Down Expand Up @@ -202,7 +204,13 @@ - (void)forceRefreshAutocompleteText

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if ([text isEqualToString:@". "]) return NO;
if (self.autocompleted) {
if ([text isEqualToString:@". "]) {
self.autocompleted = NO;
return NO;
}
}

if (self.innerTextViewDelegate && [self.innerTextViewDelegate respondsToSelector:@selector(textView:shouldChangeTextInRange:replacementText:)]) {
return [self.innerTextViewDelegate textView:textView shouldChangeTextInRange:range replacementText:text];
}
Expand Down Expand Up @@ -285,6 +293,8 @@ - (void)autocompleteText:(id)sender
self.autocompleteLabel.hidden = NO;

[self commitAutocompleteText];

self.autocompleted = YES;

// This is necessary because committing the autocomplete text changes the text field's text, but for some reason UITextView doesn't post the UITextViewTextDidChangeNotification notification on its own
[[NSNotificationCenter defaultCenter] postNotificationName:UITextViewTextDidChangeNotification object:self];
Expand Down

0 comments on commit 53e4536

Please sign in to comment.