Created
July 29, 2009 23:09
-
-
Save mkhl/158450 to your computer and use it in GitHub Desktop.
Replace triple dots with proper ellipses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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