diff --git a/ios/inputAttributesManager/InputAttributesManager.mm b/ios/inputAttributesManager/InputAttributesManager.mm index 3d844da54..f299b5398 100644 --- a/ios/inputAttributesManager/InputAttributesManager.mm +++ b/ios/inputAttributesManager/InputAttributesManager.mm @@ -130,6 +130,22 @@ - (void)handleDirtyRangesStyling { [_dirtyRanges removeAllObjects]; } +- (void)restoreInlineStylesPresentInRange:(NSRange)range + intoAttrs:(NSMutableDictionary *)attrs { + for (StyleBase *style in _input->stylesDict.allValues) { + if ([style isParagraph]) + continue; + if ([_removedTypingAttributes containsObject:[style getKey]]) + continue; + + AttributeEntry *entry = [style getEntryIfPresent:range]; + if (entry == nullptr) + continue; + + attrs[entry.key] = entry.value; + } +} + - (void)manageTypingAttributesWithOnlySelection:(BOOL)onlySelectionChanged { _recentOnlySelectionStatus = onlySelectionChanged; EnrichedInputTextView *textView = _input->textView; @@ -155,6 +171,16 @@ - (void)manageTypingAttributesWithOnlySelection:(BOOL)onlySelectionChanged { [ParagraphAttributesUtils resetTypingAttributes:_input preservingAlignment:savedAlignment]; + + // newlines could have been made within a valid inline style, so + // we want to preserve typingAttributes so they are correctly + // acknowledged when typing + if (paragraphRange.length == 1) { + NSMutableDictionary *newAttrs = [textView.typingAttributes mutableCopy]; + [self restoreInlineStylesPresentInRange:paragraphRange + intoAttrs:newAttrs]; + textView.typingAttributes = newAttrs; + } return; } } @@ -191,23 +217,10 @@ - (void)manageTypingAttributesWithOnlySelection:(BOOL)onlySelectionChanged { // getEntryIfPresent properly returns nullptr for styles that we don't want to // extend this way. Attributes from _removedTypingAttributes aren't added // because they were just removed. - for (StyleBase *style in _input->stylesDict.allValues) { - if ([style isParagraph]) - continue; - if ([_removedTypingAttributes containsObject:[style getKey]]) - continue; - - AttributeEntry *entry = nullptr; - - if (selectedRange.location > 0) { - entry = - [style getEntryIfPresent:NSMakeRange(selectedRange.location - 1, 1)]; - } - - if (entry == nullptr) - continue; - - newAttrs[entry.key] = entry.value; + if (selectedRange.location > 0) { + [self restoreInlineStylesPresentInRange:NSMakeRange( + selectedRange.location - 1, 1) + intoAttrs:newAttrs]; } // Apply active styles to typing attributes only for styles that require it so