diff --git a/Hakawai/Core/HKWTextView+Plugins.h b/Hakawai/Core/HKWTextView+Plugins.h index ba911aa..452f6df 100644 --- a/Hakawai/Core/HKWTextView+Plugins.h +++ b/Hakawai/Core/HKWTextView+Plugins.h @@ -186,4 +186,10 @@ typedef NS_ENUM(NSInteger, HKWAccessoryViewMode) { */ @property (nonatomic, readonly) UIColor *textColorSetByApp; +/*! + If the app explicitly set the text view's typingAttributes return the most recent attributes set by the app. + If the app never set the text color, return nil. + */ +@property (nonatomic, readonly) NSDictionary *typingAttributesSetByApp; + @end diff --git a/Hakawai/Core/HKWTextView.m b/Hakawai/Core/HKWTextView.m index 7413ef7..e502171 100644 --- a/Hakawai/Core/HKWTextView.m +++ b/Hakawai/Core/HKWTextView.m @@ -117,6 +117,7 @@ - (id)awakeAfterUsingCoder:(__unused NSCoder *)aDecoder { replacement.font = self.font; replacement.fontSetByApp = self.font; + replacement.typingAttributesSetByApp = self.typingAttributes; replacement.clearsOnInsertion = NO; replacement.selectable = self.selectable; @@ -708,6 +709,13 @@ - (void)setFont:(UIFont *)font { } } +- (void)setTypingAttributes:(NSDictionary *)typingAttributes { + [super setTypingAttributes:typingAttributes]; + if (typingAttributes) { + self.typingAttributesSetByApp = typingAttributes; + } +} + - (NSMutableDictionary *)simplePluginsDictionary { if (!_simplePluginsDictionary) { _simplePluginsDictionary = [NSMutableDictionary dictionary]; diff --git a/Hakawai/Core/_HKWTextView.h b/Hakawai/Core/_HKWTextView.h index 810f1f6..0ca2abf 100644 --- a/Hakawai/Core/_HKWTextView.h +++ b/Hakawai/Core/_HKWTextView.h @@ -108,9 +108,10 @@ @property (nonatomic) BOOL overridingSpellChecking; -#pragma mark - Other proeprties +#pragma mark - Other properties @property (nonatomic, strong, readwrite) UIFont *fontSetByApp; @property (nonatomic, strong, readwrite) UIColor *textColorSetByApp; +@property (nonatomic, strong, readwrite) NSDictionary *typingAttributesSetByApp; @end diff --git a/Hakawai/Mentions/HKWMentionsPluginV1.m b/Hakawai/Mentions/HKWMentionsPluginV1.m index 02cb5f8..4516d80 100644 --- a/Hakawai/Mentions/HKWMentionsPluginV1.m +++ b/Hakawai/Mentions/HKWMentionsPluginV1.m @@ -488,12 +488,19 @@ - (BOOL)stringValidForMentionsCreation:(NSString *)string { dictionary and, if applicable, restoring default attributes from the parent text view. */ - (NSDictionary *)typingAttributesByStrippingMentionAttributes:(NSDictionary *)originalAttributes { + __strong __auto_type parentTextView = self.parentTextView; + + // If we have the typing attibutes we don't need to try to rip out the selected/unselected attributes + if (parentTextView.typingAttributesSetByApp) { + return parentTextView.typingAttributesSetByApp; + } + NSMutableDictionary *d = [originalAttributes mutableCopy]; for (NSString *key in self.mentionUnselectedAttributes) { [d removeObjectForKey:key]; } + // Restore the font and/or text color, if the app set either explicitly at any point. - __strong __auto_type parentTextView = self.parentTextView; if (parentTextView.fontSetByApp) { d[NSFontAttributeName] = parentTextView.fontSetByApp; }