diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPTextViewAdditions.h | 2 | ||||
-rw-r--r-- | Source/SPTextViewAdditions.m | 62 |
2 files changed, 62 insertions, 2 deletions
diff --git a/Source/SPTextViewAdditions.h b/Source/SPTextViewAdditions.h index f32db8fd..0a2e69b1 100644 --- a/Source/SPTextViewAdditions.h +++ b/Source/SPTextViewAdditions.h @@ -39,6 +39,8 @@ - (IBAction)doTranspose:(id)sender; - (IBAction)doRemoveDiacritics:(id)sender; - (IBAction)insertNULLvalue:(id)sender; +- (IBAction)moveSelectionLineUp:(id)sender; +- (IBAction)moveSelectionLineDown:(id)sender; - (void)makeTextSizeLarger; - (void)makeTextSizeSmaller; 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 |