From 0915f9d8dcdf2177ce700dca036a629d00178dcd Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 25 Oct 2010 11:58:03 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20to=20each=20NSTextView=20the=20poss?= =?UTF-8?q?ibility=20to=20move=20the=20current=20line=20or=20the=20selecte?= =?UTF-8?q?d=20lines=20one=20line=20up=20or=20down=20by=20using=20the=20sh?= =?UTF-8?q?ort-cuts=20^=E2=8C=98=E2=86=91/=E2=86=93=20-=20fixes=20issue=20?= =?UTF-8?q?873?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPTextViewAdditions.h | 2 ++ Source/SPTextViewAdditions.m | 62 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 2 deletions(-) (limited to 'Source') 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 -- cgit v1.2.3