From 546575b27dd98cc04c34a471e681a1cc0966df1e Mon Sep 17 00:00:00 2001 From: ricky Date: Tue, 24 Nov 2020 14:48:12 -0800 Subject: [PATCH 1/2] Create typingAttributesSetByApp to restore textView attributes --- Hakawai/Core/HKWTextView+Plugins.h | 6 ++++++ Hakawai/Core/HKWTextView.m | 8 ++++++++ Hakawai/Core/_HKWTextView.h | 3 ++- Hakawai/Mentions/HKWMentionsPluginV1.m | 9 ++++++++- 4 files changed, 24 insertions(+), 2 deletions(-) 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..d34ee8d 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; } From a0f7367d37789cba70d3ea4809dad039c4823d85 Mon Sep 17 00:00:00 2001 From: ricky Date: Tue, 24 Nov 2020 16:38:36 -0800 Subject: [PATCH 2/2] =?UTF-8?q?remove=20generics,=20since=20the=20code=20d?= =?UTF-8?q?oesn=E2=80=99t=20use=20them=20in=20other=20places?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hakawai/Core/HKWTextView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hakawai/Core/HKWTextView.m b/Hakawai/Core/HKWTextView.m index d34ee8d..e502171 100644 --- a/Hakawai/Core/HKWTextView.m +++ b/Hakawai/Core/HKWTextView.m @@ -709,7 +709,7 @@ - (void)setFont:(UIFont *)font { } } -- (void)setTypingAttributes:(NSDictionary *)typingAttributes { +- (void)setTypingAttributes:(NSDictionary *)typingAttributes { [super setTypingAttributes:typingAttributes]; if (typingAttributes) { self.typingAttributesSetByApp = typingAttributes;