diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPTextViewAdditions.h | 1 | ||||
-rw-r--r-- | Source/SPTextViewAdditions.m | 22 |
2 files changed, 23 insertions, 0 deletions
diff --git a/Source/SPTextViewAdditions.h b/Source/SPTextViewAdditions.h index e5e38d3d..95075165 100644 --- a/Source/SPTextViewAdditions.h +++ b/Source/SPTextViewAdditions.h @@ -34,5 +34,6 @@ - (IBAction)doPrecomposedStringWithCanonicalMapping:(id)sender; - (IBAction)doPrecomposedStringWithCompatibilityMapping:(id)sender; - (IBAction)doTranspose:(id)sender; +- (IBAction)doRemoveDiacritics:(id)sender; @end
\ No newline at end of file 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. */ |