aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTextViewAdditions.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-10-25 11:58:03 +0000
committerBibiko <bibiko@eva.mpg.de>2010-10-25 11:58:03 +0000
commit0915f9d8dcdf2177ce700dca036a629d00178dcd (patch)
tree0ce5b8a63e6596eb1a5a9cee1a37859915159865 /Source/SPTextViewAdditions.m
parentb3cef17561a6a271ecdf6bbd0a359f1dadfbaf0a (diff)
downloadsequelpro-0915f9d8dcdf2177ce700dca036a629d00178dcd.tar.gz
sequelpro-0915f9d8dcdf2177ce700dca036a629d00178dcd.tar.bz2
sequelpro-0915f9d8dcdf2177ce700dca036a629d00178dcd.zip
• added to each NSTextView the possibility to move the current line or the selected lines one line up or down by using the short-cuts ^⌘↑/↓
- fixes issue 873
Diffstat (limited to 'Source/SPTextViewAdditions.m')
-rw-r--r--Source/SPTextViewAdditions.m62
1 files changed, 60 insertions, 2 deletions
diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m
index cab4382c..5c938d21 100644
--- a/Source/SPTextViewAdditions.m
+++ b/Source/SPTextViewAdditions.m
@@ -399,7 +399,65 @@
}
-/*
+/**
+ * Move selected lines or current line one line up
+ */
+- (IBAction)moveSelectionLineUp:(id)sender;
+{
+ NSRange currentSelection = [self selectedRange];
+ NSRange lineRange = [[self string] lineRangeForRange:currentSelection];
+ if(lineRange.location > 0) {
+ NSRange beforeLineRange = [[self string] lineRangeForRange:NSMakeRange(lineRange.location-1, 0)];
+ NSRange insertPoint = NSMakeRange(beforeLineRange.location, 0);
+ NSString *currentLine = [[self string] substringWithRange:lineRange];
+ BOOL lastLine = NO;
+ if([currentLine characterAtIndex:[currentLine length]-1] != '\n') {
+ currentLine = [NSString stringWithFormat:@"%@\n", currentLine];
+ lastLine = YES;
+ }
+ [self setSelectedRange:lineRange];
+ [self insertText:@""];
+ [self setSelectedRange:insertPoint];
+ [self insertText:currentLine];
+ if(lastLine) {
+ [self setSelectedRange:NSMakeRange([[self string] length]-1,1)];
+ [self insertText:@""];
+
+ }
+ if(currentSelection.length)
+ insertPoint.length+=[currentLine length];
+ [self setSelectedRange:insertPoint];
+ }
+}
+
+/**
+ * Move selected lines or current line one line down
+ */
+- (IBAction)moveSelectionLineDown:(id)sender
+{
+
+ NSRange currentSelection = [self selectedRange];
+ NSRange lineRange = [[self string] lineRangeForRange:currentSelection];
+ if(NSMaxRange(lineRange) < [[self string] length]) {
+ NSRange afterLineRange = [[self string] lineRangeForRange:NSMakeRange(NSMaxRange(lineRange)+1, 0)];
+ NSRange insertPoint = NSMakeRange(lineRange.location + afterLineRange.length, 0);
+ NSString *currentLine = [[self string] substringWithRange:lineRange];
+ [self setSelectedRange:lineRange];
+ [self insertText:@""];
+ [self setSelectedRange:insertPoint];
+ if([[self string] characterAtIndex:insertPoint.location-1] != '\n') {
+ [self insertText:@"\n"];
+ insertPoint.location++;
+ currentLine = [currentLine substringToIndex:[currentLine length]-1];
+ }
+ [self insertText:currentLine];
+ if(currentSelection.length)
+ insertPoint.length+=[currentLine length];
+ [self setSelectedRange:insertPoint];
+ }
+}
+
+/**
* Increase the textView's font size by 1
*/
- (void)makeTextSizeLarger
@@ -428,7 +486,7 @@
#pragma mark -
#pragma mark multi-touch trackpad support
-/*
+/**
* Trackpad two-finger zooming gesture for in/decreasing the font size
*/
- (void) magnifyWithEvent:(NSEvent *)anEvent