diff --git a/ClangFormat.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/ClangFormat.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..fe06c1e --- /dev/null +++ b/ClangFormat.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/ClangFormat/TRVSClangFormat.m b/ClangFormat/TRVSClangFormat.m index 7172d44..ebc51b0 100644 --- a/ClangFormat/TRVSClangFormat.m +++ b/ClangFormat/TRVSClangFormat.m @@ -103,6 +103,13 @@ - (void)addActioningMenuItemsToFormatMenu { keyEquivalent:@""]; [formatSelectedFilesItem setTarget:self.formatter]; [self.formatMenu addItem:formatSelectedFilesItem]; + + NSMenuItem *deleteLineItem = + [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Delete Line", nil) + action:@selector(deleteLine) + keyEquivalent:@""]; + [deleteLineItem setTarget:self.formatter]; + [self.formatMenu addItem:deleteLineItem]; } - (void)addSeparatorToFormatMenu { diff --git a/ClangFormat/TRVSFormatter.h b/ClangFormat/TRVSFormatter.h index 83beee0..9bbc7f9 100644 --- a/ClangFormat/TRVSFormatter.h +++ b/ClangFormat/TRVSFormatter.h @@ -23,4 +23,6 @@ - (void)formatSelectedFiles; - (void)formatDocument:(IDESourceCodeDocument *)document; +- (void)deleteLine; + @end diff --git a/ClangFormat/TRVSFormatter.m b/ClangFormat/TRVSFormatter.m index 708bf35..f115667 100644 --- a/ClangFormat/TRVSFormatter.m +++ b/ClangFormat/TRVSFormatter.m @@ -49,6 +49,11 @@ - (void)formatSelectedCharacters { inDocument:[TRVSXcode sourceCodeDocument]]; } +- (void)deleteLine { + [[TRVSXcode textView] selectLine:nil]; + [[TRVSXcode textView] delete:nil]; +} + - (void)formatSelectedFiles { NSArray *fileNavigableItems = [TRVSXcode selectedFileNavigableItems]; @@ -106,6 +111,8 @@ - (void)formatDocument:(IDESourceCodeDocument *)document { - (void)formatRanges:(NSArray *)ranges inDocument:(IDESourceCodeDocument *)document { DVTSourceTextStorage *textStorage = [document textStorage]; + + NSRange originSelectedRange = [[TRVSXcode textView] selectedRange]; NSArray *lineRanges = [self lineRangesOfCharacterRanges:ranges usingTextStorage:textStorage]; @@ -118,13 +125,12 @@ - (void)formatRanges:(NSArray *)ranges usingTextStorage:textStorage withDocument:document]; - NSArray *selectionRanges = - [self selectionRangesAfterReplacingFragments:fragments - usingTextStorage:textStorage - withDocument:document]; - - if (selectionRanges.count > 0) - [[TRVSXcode textView] setSelectedRanges:selectionRanges]; + [self selectionRangesAfterReplacingFragments:fragments + usingTextStorage:textStorage + withDocument:document]; + + [[TRVSXcode textView] setSelectedRange:originSelectedRange]; + [[TRVSXcode textView] centerSelectionInVisibleArea:nil]; } - (NSArray *)