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

Create typingAttributesSetByApp to restore textView typingAttributes #222

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions Hakawai/Core/HKWTextView+Plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions Hakawai/Core/HKWTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
3 changes: 2 additions & 1 deletion Hakawai/Core/_HKWTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 8 additions & 1 deletion Hakawai/Mentions/HKWMentionsPluginV1.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down