aboutsummaryrefslogtreecommitdiffstats
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
parentcb406e22d30aaf6dc62ea0917943adb555a8b3e6 (diff)
downloadsequelpro-08f14d2065632f12ba7e01acf03d3a288d3b6a39.tar.gz
sequelpro-08f14d2065632f12ba7e01acf03d3a288d3b6a39.tar.bz2
sequelpro-08f14d2065632f12ba7e01acf03d3a288d3b6a39.zip
• ADDED: - (IBAction)doTranspose:(id)sender;
- Note: not yet combining-diacritics-safe!
-rw-r--r--Interfaces/English.lproj/MainMenu.xib14
-rw-r--r--Source/SPTextViewAdditions.h1
-rw-r--r--Source/SPTextViewAdditions.m57
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 @@
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="854"/>
+ <integer value="846"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -4200,6 +4200,14 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
</object>
<int key="connectionID">903</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">doTranspose:</string>
+ <reference key="source" ref="63651044"/>
+ <reference key="destination" ref="975213454"/>
+ </object>
+ <int key="connectionID">904</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -7702,7 +7710,7 @@ w6gg4oaSIGZhY2FkZV0</string>
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">903</int>
+ <int key="maxID">904</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -7827,6 +7835,7 @@ w6gg4oaSIGZhY2FkZV0</string>
<string>doSelectionLowerCase:</string>
<string>doSelectionTitleCase:</string>
<string>doSelectionUpperCase:</string>
+ <string>doTranspose:</string>
<string>selectCurrentLine:</string>
<string>selectCurrentWord:</string>
</object>
@@ -7841,6 +7850,7 @@ w6gg4oaSIGZhY2FkZV0</string>
<string>id</string>
<string>id</string>
<string>id</string>
+ <string>id</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
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