diff --git a/Autocomplete/Sources/Controllers/ZPLSuggestionController.m b/Autocomplete/Sources/Controllers/ZPLSuggestionController.m index 515dc84..1fc2775 100644 --- a/Autocomplete/Sources/Controllers/ZPLSuggestionController.m +++ b/Autocomplete/Sources/Controllers/ZPLSuggestionController.m @@ -113,6 +113,8 @@ - (void)reloadSuggestionsForTextView:(NSTextView *)textView { NSMutableArray *suggestions = [NSMutableArray array]; for (ZPLEmoji *emoji in self.emojiController.emojis) { + BOOL suggestionAdded = NO; + for (NSString *alias in emoji.aliases) { if ([alias hasPrefix:keyword]) { ZPLSuggestion *suggestion = [[ZPLSuggestion alloc] init]; @@ -120,8 +122,9 @@ - (void)reloadSuggestionsForTextView:(NSTextView *)textView { suggestion.alias = alias; [suggestions addObject:suggestion]; + suggestionAdded = YES; - continue; + break; } NSArray *aliasComponents = [alias componentsSeparatedByString:ZPLEmojiAliasSeparator]; @@ -137,11 +140,29 @@ - (void)reloadSuggestionsForTextView:(NSTextView *)textView { suggestion.alias = alias; [suggestions addObject:suggestion]; + suggestionAdded = YES; break; } } } + + if (suggestionAdded) { + continue; + } + + for (NSString *tag in emoji.tags) { + if ([tag hasPrefix:keyword]) { + ZPLSuggestion *suggestion = [[ZPLSuggestion alloc] init]; + suggestion.emoji = emoji; + suggestion.alias = [[emoji aliases] firstObject]; + + [suggestions addObject:suggestion]; + suggestionAdded = YES; + + break; + } + } } return suggestions; diff --git a/Autocomplete/Sources/Models/ZPLEmoji.h b/Autocomplete/Sources/Models/ZPLEmoji.h index 74043f4..d137561 100644 --- a/Autocomplete/Sources/Models/ZPLEmoji.h +++ b/Autocomplete/Sources/Models/ZPLEmoji.h @@ -30,8 +30,9 @@ extern NSString * const ZPLEmojiAliasSeparator; @interface ZPLEmoji : NSObject -@property (strong, nonatomic) NSArray *aliases; @property (copy, nonatomic) NSString *value; +@property (strong, nonatomic) NSArray *aliases; +@property (strong, nonatomic) NSArray *tags; - (instancetype)initWithDictionary:(NSDictionary *)dictionary; diff --git a/Autocomplete/Sources/Models/ZPLEmoji.m b/Autocomplete/Sources/Models/ZPLEmoji.m index 0a8c8dd..58f4019 100644 --- a/Autocomplete/Sources/Models/ZPLEmoji.m +++ b/Autocomplete/Sources/Models/ZPLEmoji.m @@ -30,7 +30,12 @@ static NSString * const ZPLEmojiValueDictionaryKey = @"emoji"; static NSString * const ZPLEmojiAliasesDictionaryKey = @"aliases"; +static NSString * const ZPLEmojiTagsDictionaryKey = @"tags"; static NSString * const ZPLEmojiUnicodeVersionDictionaryKey = @"unicode_version"; +static NSString * const ZPLEmojiCategoryDictionaryKey = @"category"; +static NSString * const ZPLEmojiFlagsCategoryDictionaryValue = @"Flags"; + +static NSString * const ZPLEmojiFlagTag = @"flag"; static const NSOperatingSystemVersion ZPLEmojiUnicode8OperationSystemVersion = {.majorVersion = 10, .minorVersion = 11, .patchVersion = 5}; static const NSOperatingSystemVersion ZPLEmojiUnicode9OperationSystemVersion = {.majorVersion = 10, .minorVersion = 12, .patchVersion = 2}; @@ -59,14 +64,26 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary { NSString *value = (NSString *)[dictionary objectForKey:ZPLEmojiValueDictionaryKey]; NSArray *aliases = (NSArray *)[dictionary objectForKey:ZPLEmojiAliasesDictionaryKey]; + NSArray *tags = (NSArray *)[dictionary objectForKey:ZPLEmojiTagsDictionaryKey]; NSString *unicodeVersion = (NSString *)[dictionary objectForKey:ZPLEmojiUnicodeVersionDictionaryKey]; if (!value || !aliases || aliases.count == 0 || !unicodeVersion || ![ZPLEmoji supportsUnicodeVersion:unicodeVersion]) { return nil; } + if (!tags) { + tags = [NSArray array]; + } + + NSString *category = (NSString *)[dictionary objectForKey:ZPLEmojiCategoryDictionaryKey]; + + if ([category isEqualToString:ZPLEmojiFlagsCategoryDictionaryValue] && ![tags containsObject:ZPLEmojiFlagTag]) { + tags = [tags arrayByAddingObject:ZPLEmojiFlagTag]; + } + _value = [value copy]; _aliases = aliases; + _tags = tags; return self; }