Skip to content

Commit

Permalink
Merge pull request #142 from mschouest/master
Browse files Browse the repository at this point in the history
Add flag to reverse order of mention selection delegate callbacks
  • Loading branch information
Binya Koatz authored Nov 25, 2019
2 parents 4697883 + 3f08fea commit 9fcc8a6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Hakawai/Core/HKWTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ NS_ASSUME_NONNULL_BEGIN

+ (BOOL) enableExperimentalDeadLockFix;
+ (BOOL) enableKoreanMentionsFix;
+ (BOOL) enableMentionSelectFix;
+ (void) setEnableExperimentalDeadLockFix:(BOOL)enabled;
+ (void) setEnableKoreanMentionsFix:(BOOL)enabled;
+ (void) setEnableMentionSelectFix:(BOOL)enabled;

#pragma mark - Initialization

Expand Down
8 changes: 8 additions & 0 deletions Hakawai/Core/HKWTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ @interface HKWTextView () <UITextViewDelegate, HKWAbstractionLayerDelegate, NSTe

static BOOL enableExperimentalDeadLockFix = NO;
static BOOL enableKoreanMentionsFix = NO;
static BOOL enableMentionSelectFix = NO;

@implementation HKWTextView

Expand All @@ -51,6 +52,13 @@ + (void)setEnableKoreanMentionsFix:(BOOL)enabled {
enableKoreanMentionsFix = enabled;
}

+ (BOOL)enableMentionSelectFix {
return enableMentionSelectFix;
}
+ (void)setEnableMentionSelectFix:(BOOL)enabled {
enableMentionSelectFix = enabled;
}

#pragma mark - Lifecycle

- (instancetype _Nonnull)initWithFrame:(CGRect)frame textContainer:(nullable __unused NSTextContainer *)textContainer {
Expand Down
11 changes: 9 additions & 2 deletions Hakawai/Mentions/HKWMentionsCreationStateMachine.m
Original file line number Diff line number Diff line change
Expand Up @@ -927,8 +927,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
mention.metadata = [entity entityMetadata];
self.state = HKWMentionsCreationStateQuiescent;
__strong __auto_type delegate = self.delegate;
[delegate createMention:mention startingLocation:self.startingLocation];
[delegate selected:entity atIndexPath:indexPath];
if (HKWTextView.enableMentionSelectFix) {
// Delegate selected callback should fire prior to creationMention which triggers textView callbacks
[delegate selected:entity atIndexPath:indexPath];
[delegate createMention:mention startingLocation:self.startingLocation];
} else {
[delegate createMention:mention startingLocation:self.startingLocation];
[delegate selected:entity atIndexPath:indexPath];
}
}
Expand Down

0 comments on commit 9fcc8a6

Please sign in to comment.