Skip to content

Commit

Permalink
feat: place import command line tool
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshengzhi committed Jun 22, 2024
1 parent e698d43 commit 8bf707f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions SZXcodeEditorExtension/NSArray+SZAddition.m
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ - (NSRange)sz_importLinesRange {
if (tempArray.count) {
for (NSValue *value in tempArray) {
NSRange range = [value rangeValue];
BOOL allImport = YES;
BOOL allImport = range.length > 2;
NSInteger macroStart = range.location;
NSInteger macroEnd = range.location + range.length;
for (NSInteger idx = macroStart + 1; idx < macroEnd - 1; idx++) {
for (NSInteger idx = macroStart + 1; idx < macroEnd; idx++) {
NSString *line = self[idx];
if (![line sz_isImportLine]) {
allImport = NO;
Expand All @@ -255,7 +255,7 @@ - (NSRange)sz_importLinesRange {
}
}
NSInteger count = 0;
if (start != NSNotFound) {
if (start != NSNotFound && end != NSNotFound) {
count = end + 1 - start;
}
return NSMakeRange(start, count);
Expand Down
6 changes: 5 additions & 1 deletion SZXcodeEditorExtension/SZPlaceImportHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ @implementation SZPlaceImportHelper
+ (NSArray<NSString *> *)processLines:(NSArray<NSString *> *)lines
selections:(nullable NSArray<SZSourceTextRange *> *)selections
commandIdentifier:(nullable NSString *)commandIdentifier {
NSRange importRange = [lines sz_importLinesRange];
if (importRange.location == NSNotFound) {
return lines;
}

NSMutableArray *linesMutable = [lines mutableCopy];
__block NSInteger insertIndex = 0;
NSRange importRange = [linesMutable sz_importLinesRange];
if (importRange.location != NSNotFound) {
insertIndex = NSMaxRange(importRange);
}
Expand Down

0 comments on commit 8bf707f

Please sign in to comment.