From 08f14d2065632f12ba7e01acf03d3a288d3b6a39 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Sun, 5 Apr 2009 20:34:49 +0000 Subject: =?UTF-8?q?=E2=80=A2=20ADDED:=20-=20(IBAction)doTranspose:(id)send?= =?UTF-8?q?er;=20-=20Note:=20not=20yet=20combining-diacritics-safe!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/MainMenu.xib | 14 +++++++-- Source/SPTextViewAdditions.h | 1 + Source/SPTextViewAdditions.m | 57 +++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/Interfaces/English.lproj/MainMenu.xib b/Interfaces/English.lproj/MainMenu.xib index 50e6e528..9515ba4c 100644 --- a/Interfaces/English.lproj/MainMenu.xib +++ b/Interfaces/English.lproj/MainMenu.xib @@ -8,7 +8,7 @@ 353.00 YES - + YES @@ -4200,6 +4200,14 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA 903 + + + doTranspose: + + + + 904 + @@ -7702,7 +7710,7 @@ w6gg4oaSIGZhY2FkZV0 - 903 + 904 @@ -7827,6 +7835,7 @@ w6gg4oaSIGZhY2FkZV0 doSelectionLowerCase: doSelectionTitleCase: doSelectionUpperCase: + doTranspose: selectCurrentLine: selectCurrentWord: @@ -7841,6 +7850,7 @@ w6gg4oaSIGZhY2FkZV0 id id id + id diff --git a/Source/SPTextViewAdditions.h b/Source/SPTextViewAdditions.h index 0aaa4cde..e5e38d3d 100644 --- a/Source/SPTextViewAdditions.h +++ b/Source/SPTextViewAdditions.h @@ -33,5 +33,6 @@ - (IBAction)doDecomposedStringWithCompatibilityMapping:(id)sender; - (IBAction)doPrecomposedStringWithCanonicalMapping:(id)sender; - (IBAction)doPrecomposedStringWithCompatibilityMapping:(id)sender; +- (IBAction)doTranspose:(id)sender; @end \ No newline at end of file diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index 6031399d..4c467a22 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -204,5 +204,62 @@ } +/* + * Transpose adjacent characters, or if a selection is given reverse the selected characters. + * If the caret is at the absolute end of the text field it transpose the two last charaters. + * If the caret is at the absolute beginnng of the text field do nothing. + * TODO: not yet combining-diacritics-safe + */ +- (IBAction)doTranspose:(id)sender +{ + NSRange curRange = [self selectedRange]; + NSRange workingRange = curRange; + + if(!curRange.length) + @try // caret is in between two chars + { + if(curRange.location+1 >= [[self string] length]) + { + // caret is at the end of a text field + // transpose last two characters + [self moveLeftAndModifySelection:self]; + [self moveLeftAndModifySelection:self]; + workingRange = [self selectedRange]; + } + else if(curRange.location == 0) + { + // caret is at the beginning of the text field + // do nothing + workingRange.length = 0; + } + else + { + // caret is in between two characters + // reverse adjacent characters + NSRange twoCharRange = NSMakeRange(curRange.location-1, 2); + [self setSelectedRange:twoCharRange]; + workingRange = twoCharRange; + } + } + @catch(id ae) + { workingRange.length = 0; } + + + + // reverse string : TODO not yet combining diacritics safe! + if(workingRange.length > 1) + { + NSMutableString *reversedStr; + unsigned long len = workingRange.length; + reversedStr = [NSMutableString stringWithCapacity:len]; + while (len > 0) + [reversedStr appendString: + [NSString stringWithFormat:@"%C", [[self string] characterAtIndex:--len+workingRange.location]]]; + + [self insertText:reversedStr]; + [self setSelectedRange:curRange]; + } +} + @end -- cgit v1.2.3