diff --git a/KSImageNamed.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/KSImageNamed.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..8a78bd0 --- /dev/null +++ b/KSImageNamed.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/KSImageNamed.xcodeproj/project.xcworkspace/xcshareddata/KSImageNamed.xccheckout b/KSImageNamed.xcodeproj/project.xcworkspace/xcshareddata/KSImageNamed.xccheckout new file mode 100644 index 0000000..0688c88 --- /dev/null +++ b/KSImageNamed.xcodeproj/project.xcworkspace/xcshareddata/KSImageNamed.xccheckout @@ -0,0 +1,41 @@ + + + + + IDESourceControlProjectFavoriteDictionaryKey + + IDESourceControlProjectIdentifier + 38EA5A0B-F27C-46AF-84C4-880AF2D73FBE + IDESourceControlProjectName + KSImageNamed + IDESourceControlProjectOriginsDictionary + + C2F7F2B06ED7506D9B6499106F8DB5F0850044C7 + https://github.com/musiczone/KSImageNamed-Xcode.git + + IDESourceControlProjectPath + KSImageNamed.xcodeproj + IDESourceControlProjectRelativeInstallPathDictionary + + C2F7F2B06ED7506D9B6499106F8DB5F0850044C7 + ../.. + + IDESourceControlProjectURL + https://github.com/musiczone/KSImageNamed-Xcode.git + IDESourceControlProjectVersion + 111 + IDESourceControlProjectWCCIdentifier + C2F7F2B06ED7506D9B6499106F8DB5F0850044C7 + IDESourceControlProjectWCConfigurations + + + IDESourceControlRepositoryExtensionIdentifierKey + public.vcs.git + IDESourceControlWCCIdentifierKey + C2F7F2B06ED7506D9B6499106F8DB5F0850044C7 + IDESourceControlWCCName + KSImageNamed-Xcode + + + + diff --git a/KSImageNamed/DVTTextCompletionController+KSImageNamed.m b/KSImageNamed/DVTTextCompletionController+KSImageNamed.m index acd5f53..277af99 100644 --- a/KSImageNamed/DVTTextCompletionController+KSImageNamed.m +++ b/KSImageNamed/DVTTextCompletionController+KSImageNamed.m @@ -21,17 +21,36 @@ + (void)load - (BOOL)swizzle_acceptCurrentCompletion { - BOOL success = [self swizzle_acceptCurrentCompletion]; + NSRange selectedRange = [[self textView] selectedRange]; + + id item = nil; + if ([self.textView.textStorage respondsToSelector:@selector(sourceModelItemAtCharacterIndex:)]) { + item = [self.textView.textStorage sourceModelItemAtCharacterIndex:selectedRange.location]; //-2.插入时会增加@" + } else { + item = [[self.textView.textStorage sourceModelService] sourceModelItemAtCharacterIndex:selectedRange.location]; + } + NSRange itemRange = [item range]; +// NSLog(@"替换前,itemRange: %@ selectRange:%@",NSStringFromRange(itemRange),NSStringFromRange(selectedRange)); + NSString *itemString = [[self.textView.textStorage string] substringWithRange:itemRange]; +// NSLog(@"替换前,itemString:%@",itemString); + + BOOL success = [self swizzle_acceptCurrentCompletion]; + if (success) { @try { NSRange range = [[self textView] selectedRange]; + + if ([itemString hasPrefix:@"@\""]&&[itemString hasSuffix:@"\""]){ + [self.textView insertText:@"" replacementRange:NSMakeRange(range.location, itemRange.location+itemRange.length-range.location+1+2)]; + [self.textView insertText:@"" replacementRange:NSMakeRange(itemRange.location, 2)]; + } for (NSString *nextClassAndMethod in [[KSImageNamed sharedPlugin] completionStringsForType:KSImageNamedCompletionStringTypeClassAndMethod]) { //If an autocomplete causes imageNamed: to get inserted, remove the token and immediately pop up autocomplete if (range.location > [nextClassAndMethod length]) { NSString *insertedString = [[[self textView] string] substringWithRange:NSMakeRange(range.location - [nextClassAndMethod length], [nextClassAndMethod length])]; - +// NSLog(@"准备插入替换.....%@,%@",insertedString,nextClassAndMethod); if ([insertedString isEqualToString:nextClassAndMethod]) { [[self textView] insertText:@"" replacementRange:range]; [self _showCompletionsAtCursorLocationExplicitly:YES]; diff --git a/KSImageNamed/KSImageNamed.m b/KSImageNamed/KSImageNamed.m index 7c7674d..a0f3bb0 100644 --- a/KSImageNamed/KSImageNamed.m +++ b/KSImageNamed/KSImageNamed.m @@ -231,8 +231,12 @@ - (NSArray *)_imageCompletionsForIndex:(id)index NSString *normalFileName; BOOL skip = NO; BOOL is2x = NO; + BOOL is3x = NO; - if ([imageName hasSuffix:@"@2x"]) { + if ([imageName hasSuffix:@"@3x"]) { + normalFileName = [[imageName substringToIndex:[imageName length] - 3] stringByAppendingFormat:@".%@", [fileName pathExtension]]; + is3x = YES; + }else if ([imageName hasSuffix:@"@2x"]) { normalFileName = [[imageName substringToIndex:[imageName length] - 3] stringByAppendingFormat:@".%@", [fileName pathExtension]]; is2x = YES; } else if ([imageName hasSuffix:@"@2x~ipad"]) { @@ -246,7 +250,9 @@ - (NSArray *)_imageCompletionsForIndex:(id)index KSImageNamedIndexCompletionItem *existingCompletionItem = [imageCompletionItems objectForKey:normalFileName]; if (existingCompletionItem) { - if (is2x) { + if (is3x) { + existingCompletionItem.has2x = YES; + }else if (is2x) { existingCompletionItem.has2x = YES; } else { existingCompletionItem.has1x = YES; diff --git a/KSImageNamed/KSImageNamedIndexCompletionItem.h b/KSImageNamed/KSImageNamedIndexCompletionItem.h index dd70396..19e1764 100644 --- a/KSImageNamed/KSImageNamedIndexCompletionItem.h +++ b/KSImageNamed/KSImageNamedIndexCompletionItem.h @@ -107,6 +107,7 @@ @property(nonatomic, strong, readonly) NSString *fileName; @property(nonatomic, assign) BOOL has1x; @property(nonatomic, assign) BOOL has2x; +@property(nonatomic, assign) BOOL has3x; @property(nonatomic, assign) BOOL forSwift; @property(nonatomic, assign, getter=isInAssetCatalog, readonly) BOOL inAssetCatalog; diff --git a/KSImageNamed/KSImageNamedIndexCompletionItem.m b/KSImageNamed/KSImageNamedIndexCompletionItem.m index 62f6212..efad764 100644 --- a/KSImageNamed/KSImageNamedIndexCompletionItem.m +++ b/KSImageNamed/KSImageNamedIndexCompletionItem.m @@ -115,12 +115,20 @@ - (NSString *)displayText { NSString *displayFormat = @"%@ (%@)"; - if (self.has1x && self.has2x) { + if (self.has1x && self.has2x && self.has3x) { + displayFormat = @"%@ (%@, 1x and 2x and 3x)"; + }if (self.has2x && self.has3x) { + displayFormat = @"%@ (%@, 2x and 3x)"; + }if (self.has1x && self.has3x) { + displayFormat = @"%@ (%@, 1x and 3x)"; + }else if (self.has1x && self.has2x) { displayFormat = @"%@ (%@, 1x and 2x)"; } else if (self.has1x) { displayFormat = @"%@ (%@, 1x only)"; } else if (self.has2x) { displayFormat = @"%@ (%@, 2x only)"; + }else if (self.has3x){ + displayFormat = @"%@ (%@, 3x only)"; } return [NSString stringWithFormat:displayFormat, [self _imageNamedText], [[self fileURL] pathExtension]]; @@ -131,7 +139,7 @@ - (NSString *)_fileName NSString *fileName = [[self fileURL] lastPathComponent]; NSString *imageName = [fileName stringByDeletingPathExtension]; - if ([imageName hasSuffix:@"@2x"]) { + if ([imageName hasSuffix:@"@2x"] || [imageName hasSuffix:@"@3x"]) { fileName = [[imageName substringToIndex:[imageName length] - 3] stringByAppendingFormat:@".%@", [fileName pathExtension]]; } else if ([imageName hasSuffix:@"@2x~ipad"]) { //2x iPad images need to be handled separately since (image~ipad and image@2x~ipad are valid pairs) diff --git a/KSImageNamed/XcodeMisc.h b/KSImageNamed/XcodeMisc.h index f985a7b..1b315bf 100644 --- a/KSImageNamed/XcodeMisc.h +++ b/KSImageNamed/XcodeMisc.h @@ -69,6 +69,7 @@ - (id)stringConstantAtLocation:(unsigned long long)arg1; //DVTSourceModel - (id)previousItem; //DVTSourceModelItem +- (id)nextItem; - (id)_listWindowController; //DVTTextCompletionSession @end