aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPStringAdditions.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2009-04-02 01:23:26 +0000
committerrowanbeentje <rowan@beent.je>2009-04-02 01:23:26 +0000
commit00910549fefaaa0954aa080a3ec1be5a4746062b (patch)
tree896bc68f6426e58be635ef0238aad7b045057651 /Source/SPStringAdditions.m
parent8fd7a25952b3d5317a22e14c83af06b56c32710a (diff)
downloadsequelpro-00910549fefaaa0954aa080a3ec1be5a4746062b.tar.gz
sequelpro-00910549fefaaa0954aa080a3ec1be5a4746062b.tar.bz2
sequelpro-00910549fefaaa0954aa080a3ec1be5a4746062b.zip
- Add a new "gear" action menu underneath the custom query view, including a number of items:
- Add menu commands for "Run All" and "Run Selected", with additional keyboard shortcuts - cmd-R for Run all, addressing #137 - Add menu commands for indenting text, outdenting text, and to show autocompletion is available - Add menu commands to toggle autopairing and autoindenting - Also hidden menu commands for history navigation and clearing, not hooked in yet (see #207) - Add a new method to our string additions: lineRangesForRange - Add "shift right" (indent) and "shift left" (outdent) support to CMTextView, including for multiple lines
Diffstat (limited to 'Source/SPStringAdditions.m')
-rw-r--r--Source/SPStringAdditions.m33
1 files changed, 33 insertions, 0 deletions
diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m
index 74c98b4f..2c719f6c 100644
--- a/Source/SPStringAdditions.m
+++ b/Source/SPStringAdditions.m
@@ -136,6 +136,39 @@
return quotedString;
}
+// -------------------------------------------------------------------------------
+// lineRangesForRange
+//
+// Returns an array of serialised NSRanges, each representing a line within the string
+// which is at least partially covered by the NSRange supplied.
+// Each line includes the line termination character(s) for the line. As per
+// lineRangeForRange, lines are split by CR, LF, CRLF, U+2028 (Unicode line separator),
+// or U+2029 (Unicode paragraph separator).
+// -------------------------------------------------------------------------------
+- (NSArray *)lineRangesForRange:(NSRange)aRange
+{
+ NSMutableArray *lineRangesArray = [NSMutableArray array];
+ NSRange currentLineRange;
+
+ // Check that the range supplied is valid - if not return an empty array.
+ if (aRange.location == NSNotFound || aRange.location + aRange.length > [self length])
+ return lineRangesArray;
+
+ // Get the range of the first string covered by the specified range, and add it to the array
+ currentLineRange = [self lineRangeForRange:NSMakeRange(aRange.location, 0)];
+ [lineRangesArray addObject:NSStringFromRange(currentLineRange)];
+
+ // Loop through until the line end matches or surpasses the end of the specified range
+ while (currentLineRange.location + currentLineRange.length < aRange.location + aRange.length) {
+ currentLineRange = [self lineRangeForRange:NSMakeRange(currentLineRange.location + currentLineRange.length, 0)];
+ [lineRangesArray addObject:NSStringFromRange(currentLineRange)];
+ }
+
+ // Return the constructed array of ranges
+ return lineRangesArray;
+}
+
+
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
/*
* componentsSeparatedByCharactersInSet: