aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTextViewAdditions.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-04-05 20:34:49 +0000
committerBibiko <bibiko@eva.mpg.de>2009-04-05 20:34:49 +0000
commit08f14d2065632f12ba7e01acf03d3a288d3b6a39 (patch)
treefdd7eb2d3dd44f7ce5459fa3a7add1dd197b9c9f /Source/SPTextViewAdditions.m
parentcb406e22d30aaf6dc62ea0917943adb555a8b3e6 (diff)
downloadsequelpro-08f14d2065632f12ba7e01acf03d3a288d3b6a39.tar.gz
sequelpro-08f14d2065632f12ba7e01acf03d3a288d3b6a39.tar.bz2
sequelpro-08f14d2065632f12ba7e01acf03d3a288d3b6a39.zip
• ADDED: - (IBAction)doTranspose:(id)sender;
- Note: not yet combining-diacritics-safe!
Diffstat (limited to 'Source/SPTextViewAdditions.m')
-rw-r--r--Source/SPTextViewAdditions.m57
1 files changed, 57 insertions, 0 deletions
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