Skip to content

Instantly share code, notes, and snippets.

@mkhl
Created July 29, 2009 23:09
Show Gist options
  • Save mkhl/158450 to your computer and use it in GitHub Desktop.
Save mkhl/158450 to your computer and use it in GitHub Desktop.
Replace triple dots with proper ellipses
// Replace triple dots with proper ellipses.
// Source: http://www.mikeabdullah.net/ellipses_and_sheepkit.html
- (BOOL)textView:(EweEyeTextView *)textView
shouldChangeTextInRange:(NSRange)range
replacementText:(NSString *)text
{
BOOL result = YES;
if ([text hasSuffix:@"."]) // Accounts for somehow entering ".."
{
NSMutableString *resultantText = [[textView text] mutableCopy];
[resultantText replaceCharactersInRange:range withString:text];
NSRange ellipsisRange =
NSMakeRange(range.location + [text length] - 3, 3);
NSString *possibleEllipsis =
[resultantText substringWithRange:ellipsisRange];
if ([possibleEllipsis isEqualToString:@"..."])
{
[resultantText replaceCharactersInRange:ellipsisRange
withString:@"…"];
[textView setText:resultantText];
NSRange selection = NSMakeRange(ellipsisRange.location + 1, 0);
[textView setSelectedRange:selection];
result = NO;
}
[resultantText release];
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment