aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTextViewAdditions.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-04-05 16:12:30 +0000
committerBibiko <bibiko@eva.mpg.de>2009-04-05 16:12:30 +0000
commitcf83a507b6732f20f3b49b453333b7e20e80037b (patch)
treeff174a8e24eef270e227aa7e534b77be087b4e2b /Source/SPTextViewAdditions.m
parentb5372b610516c06aca19f17b262ba00df611ebc9 (diff)
downloadsequelpro-cf83a507b6732f20f3b49b453333b7e20e80037b.tar.gz
sequelpro-cf83a507b6732f20f3b49b453333b7e20e80037b.tar.bz2
sequelpro-cf83a507b6732f20f3b49b453333b7e20e80037b.zip
• ADDED to SPTextViewAdditions:
- (NSRange)getRangeForCurrentWord - (IBAction)selectCurrentWord:(id)sender; - (IBAction)selectCurrentLine:(id)sender; - (IBAction)doSelectionUpperCase:(id)sender; - (IBAction)doSelectionLowerCase:(id)sender; - (IBAction)doSelectionTitleCase:(id)sender; - (IBAction)doDecomposedStringWithCanonicalMapping:(id)sender; - (IBAction)doDecomposedStringWithCompatibilityMapping:(id)sender; - (IBAction)doPrecomposedStringWithCanonicalMapping:(id)sender; - (IBAction)doPrecomposedStringWithCompatibilityMapping:(id)sender; • BOUNDED these IBAction to mainmenu.xib
Diffstat (limited to 'Source/SPTextViewAdditions.m')
-rw-r--r--Source/SPTextViewAdditions.m180
1 files changed, 180 insertions, 0 deletions
diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m
index 426cc1b5..6031399d 100644
--- a/Source/SPTextViewAdditions.m
+++ b/Source/SPTextViewAdditions.m
@@ -24,5 +24,185 @@
@implementation NSTextView (SPTextViewAdditions)
+/*
+ * Returns the range of the current word.
+ * finds: [| := caret] |word wo|rd word|
+ * If | is in between whitespaces nothing will be selected.
+ */
+- (NSRange)getRangeForCurrentWord
+{
+
+ NSRange curRange = [self selectedRange];
+ unsigned long curLocation = curRange.location;
+
+ [self moveWordLeft:self];
+ [self moveWordRightAndModifySelection:self];
+
+ unsigned long newStartRange = [self selectedRange].location;
+ unsigned long newEndRange = newStartRange + [self selectedRange].length;
+
+ // if current location does not intersect with found range
+ // then caret is at the begin of a word -> change strategy
+ if(curLocation < newStartRange || curLocation > newEndRange)
+ {
+ [self setSelectedRange:curRange];
+ [self moveWordRightAndModifySelection:self];
+ }
+
+ if([[[self string] substringWithRange:[self selectedRange]] rangeOfCharacterFromSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].location != NSNotFound)
+ [self setSelectedRange:curRange];
+
+ NSRange wordRange = [self selectedRange];
+
+ [self setSelectedRange:curRange];
+
+ return(wordRange);
+
+}
+
+/*
+ * Select current word.
+ * finds: [| := caret] |word wo|rd word|
+ * If | is in between whitespaces nothing will be selected.
+ */
+- (IBAction)selectCurrentWord:(id)sender
+{
+ [self setSelectedRange:[self getRangeForCurrentWord]];
+}
+
+/*
+ * Select current line.
+ */
+- (IBAction)selectCurrentLine:(id)sender
+{
+ [self doCommandBySelector:@selector(moveToBeginningOfLine:)];
+ [self doCommandBySelector:@selector(moveToEndOfLineAndModifySelection:)];
+}
+
+/*
+ * Change selection or current word to upper case and preserves the selection.
+ */
+- (IBAction)doSelectionUpperCase:(id)sender
+{
+ NSRange curRange = [self selectedRange];
+ NSRange selRange = (curRange.length) ? curRange : [self getRangeForCurrentWord];
+ [self setSelectedRange:selRange];
+ [self insertText:[[[self string] substringWithRange:selRange] uppercaseString]];
+ [self setSelectedRange:curRange];
+}
+
+/*
+ * Change selection or current word to lower case and preserves the selection.
+ */
+- (IBAction)doSelectionLowerCase:(id)sender
+{
+ NSRange curRange = [self selectedRange];
+ NSRange selRange = (curRange.length) ? curRange : [self getRangeForCurrentWord];
+ [self setSelectedRange:selRange];
+ [self insertText:[[[self string] substringWithRange:selRange] lowercaseString]];
+ [self setSelectedRange:curRange];
+}
+
+/*
+ * Change selection or current word to title case and preserves the selection.
+ */
+- (IBAction)doSelectionTitleCase:(id)sender
+{
+ NSRange curRange = [self selectedRange];
+ NSRange selRange = (curRange.length) ? curRange : [self getRangeForCurrentWord];
+ [self setSelectedRange:selRange];
+ [self insertText:[[[self string] substringWithRange:selRange] capitalizedString]];
+ [self setSelectedRange:curRange];
+}
+
+/*
+ * Change selection or current word according to Unicode's NFD and preserves the selection.
+ */
+- (IBAction)doDecomposedStringWithCanonicalMapping:(id)sender
+{
+ NSRange curRange = [self selectedRange];
+ NSRange selRange = (curRange.length) ? curRange : [self getRangeForCurrentWord];
+ [self setSelectedRange:selRange];
+ NSString* convString = [[[self string] substringWithRange:selRange] decomposedStringWithCanonicalMapping];
+ [self insertText:convString];
+
+ // correct range for combining characters
+ if(curRange.length)
+ [self setSelectedRange:NSMakeRange(selRange.location, [convString 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 NFKD and preserves the selection.
+ */
+- (IBAction)doDecomposedStringWithCompatibilityMapping:(id)sender
+{
+ NSRange curRange = [self selectedRange];
+ NSRange selRange = (curRange.length) ? curRange : [self getRangeForCurrentWord];
+ [self setSelectedRange:selRange];
+ NSString* convString = [[[self string] substringWithRange:selRange] decomposedStringWithCompatibilityMapping];
+ [self insertText:convString];
+
+ // correct range for combining characters
+ if(curRange.length)
+ [self setSelectedRange:NSMakeRange(selRange.location, [convString 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 NFC and preserves the selection.
+ */
+- (IBAction)doPrecomposedStringWithCanonicalMapping:(id)sender
+{
+ NSRange curRange = [self selectedRange];
+ NSRange selRange = (curRange.length) ? curRange : [self getRangeForCurrentWord];
+ [self setSelectedRange:selRange];
+ NSString* convString = [[[self string] substringWithRange:selRange] precomposedStringWithCanonicalMapping];
+ [self insertText:convString];
+
+ // correct range for combining characters
+ if(curRange.length)
+ [self setSelectedRange:NSMakeRange(selRange.location, [convString 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.
+ */
+- (IBAction)doPrecomposedStringWithCompatibilityMapping:(id)sender
+{
+ NSRange curRange = [self selectedRange];
+ NSRange selRange = (curRange.length) ? curRange : [self getRangeForCurrentWord];
+ [self setSelectedRange:selRange];
+ NSString* convString = [[[self string] substringWithRange:selRange] precomposedStringWithCompatibilityMapping];
+ [self insertText:convString];
+
+ // correct range for combining characters
+ if(curRange.length)
+ [self setSelectedRange:NSMakeRange(selRange.location, [convString 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)];
+ }
+}
+
+
@end