diff options
Diffstat (limited to 'Source/SPTextViewAdditions.m')
-rw-r--r-- | Source/SPTextViewAdditions.m | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index 4c467a22..c7491215 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -181,6 +181,28 @@ } } +- (IBAction)doRemoveDiacritics:(id)sender +{ + + NSRange curRange = [self selectedRange]; + NSRange selRange = (curRange.length) ? curRange : [self getRangeForCurrentWord]; + [self setSelectedRange:selRange]; + NSString* convString = [[[self string] substringWithRange:selRange] decomposedStringWithCanonicalMapping]; + NSArray* chars; + chars = [convString componentsSeparatedByCharactersInSet:[NSCharacterSet nonBaseCharacterSet]]; + NSString* cleanString = [chars componentsJoinedByString:@""]; + [self insertText:cleanString]; + if(curRange.length) + [self setSelectedRange:NSMakeRange(selRange.location, [cleanString length])]; + else + // if no selection place the caret at the end of the current word + { + NSRange newRange = [self getRangeForCurrentWord]; + [self setSelectedRange:NSMakeRange(newRange.location + newRange.length, 0)]; + } + +} + /* * Change selection or current word according to Unicode's NFKC to title case and preserves the selection. */ |