diff --git a/ios/EnrichedTextInputView.mm b/ios/EnrichedTextInputView.mm index a899aa629..ae59b62a6 100644 --- a/ios/EnrichedTextInputView.mm +++ b/ios/EnrichedTextInputView.mm @@ -2000,6 +2000,14 @@ - (bool)textView:(UITextView *)textView return NO; } + // To be sure, we re-run typingAttributes management right before the + // character actually lands. Sometimes, between a selection change and the + // next keystroke, typing attributes might get removed - this seems like a + // native TextKit issue. + if (textView.markedTextRange == nil && range.length == 0 && text.length > 0) { + [attributesManager repeatRecentTypingAttributesManagement]; + } + return YES; } diff --git a/ios/inputAttributesManager/InputAttributesManager.h b/ios/inputAttributesManager/InputAttributesManager.h index c0cb19df9..b4ba67a7b 100644 --- a/ios/inputAttributesManager/InputAttributesManager.h +++ b/ios/inputAttributesManager/InputAttributesManager.h @@ -13,6 +13,7 @@ - (void)didRemoveTypingAttribute:(NSString *)key; - (void)clearRemovedTypingAttributes; - (void)manageTypingAttributesWithOnlySelection:(BOOL)onlySelectionChanged; +- (void)repeatRecentTypingAttributesManagement; - (void)handleDirtyRangesStyling; - (NSSet *)customAttributesKeys; @end diff --git a/ios/inputAttributesManager/InputAttributesManager.mm b/ios/inputAttributesManager/InputAttributesManager.mm index fc07d871f..b488129d9 100644 --- a/ios/inputAttributesManager/InputAttributesManager.mm +++ b/ios/inputAttributesManager/InputAttributesManager.mm @@ -11,6 +11,7 @@ @implementation InputAttributesManager { NSMutableArray *_dirtyRanges; NSSet *_customAttributesKeys; NSMutableSet *_removedTypingAttributes; + BOOL _recentManagedTypingAttributesOnlySelection; } - (instancetype)initWithInput:(EnrichedTextInputView *)input { @@ -18,6 +19,7 @@ - (instancetype)initWithInput:(EnrichedTextInputView *)input { _input = input; _dirtyRanges = [[NSMutableArray alloc] init]; _removedTypingAttributes = [[NSMutableSet alloc] init]; + _recentManagedTypingAttributesOnlySelection = NO; // setup customAttributes NSMutableSet *_customAttrsSet = [[NSMutableSet alloc] init]; @@ -129,6 +131,7 @@ - (void)handleDirtyRangesStyling { } - (void)manageTypingAttributesWithOnlySelection:(BOOL)onlySelectionChanged { + _recentManagedTypingAttributesOnlySelection = onlySelectionChanged; EnrichedInputTextView *textView = _input->textView; NSRange selectedRange = textView.selectedRange; @@ -219,4 +222,9 @@ - (void)manageTypingAttributesWithOnlySelection:(BOOL)onlySelectionChanged { textView.typingAttributes = newAttrs; } +- (void)repeatRecentTypingAttributesManagement { + [self manageTypingAttributesWithOnlySelection: + _recentManagedTypingAttributesOnlySelection]; +} + @end