From 805139383480e3f49c3ab59b2bafba6daf78c6ac Mon Sep 17 00:00:00 2001 From: Iulian Onofrei Date: Wed, 29 Jul 2015 11:31:18 +0300 Subject: [PATCH] Moved cursor position in the middle of the comment block or at the end of the comment text --- CComment/CComment.m | 2 +- CComment/Xcode.h | 2 +- CComment/Xcode.m | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CComment/CComment.m b/CComment/CComment.m index a1499fd..4cd7054 100644 --- a/CComment/CComment.m +++ b/CComment/CComment.m @@ -88,7 +88,7 @@ - (void)doMenuAction NSString *commented = [self commentString:textView.textStorage.string range:&range]; if (commented != nil) { - [Xcode replaceCharactersInRange:range withString:commented]; + [Xcode replaceCharactersInRange:range withString:commented andOptionEnabled:[self isOptionEnabled]]; } } diff --git a/CComment/Xcode.h b/CComment/Xcode.h index 656ce02..da71447 100644 --- a/CComment/Xcode.h +++ b/CComment/Xcode.h @@ -12,7 +12,7 @@ + (id)currentEditor; + (NSTextView *)textView; -+ (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)aString; ++ (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)aString andOptionEnabled:(BOOL)optionEnabled; //+ (void)setupKeyBinding; @end diff --git a/CComment/Xcode.m b/CComment/Xcode.m index a81fafd..61a40c1 100644 --- a/CComment/Xcode.m +++ b/CComment/Xcode.m @@ -99,7 +99,7 @@ + (IDESourceCodeDocument *)sourceCodeDocument { return nil; } -+ (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)aString ++ (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)aString andOptionEnabled:(BOOL)optionEnabled { IDESourceCodeDocument * document = [self sourceCodeDocument]; if ( !document ) @@ -107,6 +107,8 @@ + (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)aString [[document textStorage] beginEditing]; [[document textStorage] replaceCharactersInRange:range withString:aString withUndoManager:[document undoManager]]; [[document textStorage] endEditing]; + + [[self textView] setSelectedRange:NSMakeRange(range.location + aString.length - (optionEnabled ? 3 : 2), 0)]; } @end