Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check emoji tags when finding suggestions #23

Merged
merged 2 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion Autocomplete/Sources/Controllers/ZPLSuggestionController.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,18 @@ - (void)reloadSuggestionsForTextView:(NSTextView *)textView {
NSMutableArray<ZPLSuggestion *> *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];
suggestion.emoji = emoji;
suggestion.alias = alias;

[suggestions addObject:suggestion];
suggestionAdded = YES;

continue;
break;
}

NSArray<NSString *> *aliasComponents = [alias componentsSeparatedByString:ZPLEmojiAliasSeparator];
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion Autocomplete/Sources/Models/ZPLEmoji.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ extern NSString * const ZPLEmojiAliasSeparator;

@interface ZPLEmoji : NSObject

@property (strong, nonatomic) NSArray<NSString *> *aliases;
@property (copy, nonatomic) NSString *value;
@property (strong, nonatomic) NSArray<NSString *> *aliases;
@property (strong, nonatomic) NSArray<NSString *> *tags;

- (instancetype)initWithDictionary:(NSDictionary *)dictionary;

Expand Down
17 changes: 17 additions & 0 deletions Autocomplete/Sources/Models/ZPLEmoji.m
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -59,14 +64,26 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary {

NSString *value = (NSString *)[dictionary objectForKey:ZPLEmojiValueDictionaryKey];
NSArray<NSString *> *aliases = (NSArray<NSString *> *)[dictionary objectForKey:ZPLEmojiAliasesDictionaryKey];
NSArray<NSString *> *tags = (NSArray<NSString *> *)[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;
}
Expand Down