@@ -128,6 +128,22 @@ - (void)handleDirtyRangesStyling {
128128 [_dirtyRanges removeAllObjects ];
129129}
130130
131+ - (void )restoreInlineStylesPresentInRange : (NSRange )range
132+ intoAttrs : (NSMutableDictionary *)attrs {
133+ for (StyleBase *style in _input->stylesDict .allValues ) {
134+ if ([style isParagraph ])
135+ continue ;
136+ if ([_removedTypingAttributes containsObject: [style getKey ]])
137+ continue ;
138+
139+ AttributeEntry *entry = [style getEntryIfPresent: range];
140+ if (entry == nullptr )
141+ continue ;
142+
143+ attrs[entry.key] = entry.value ;
144+ }
145+ }
146+
131147- (void )manageTypingAttributesWithOnlySelection : (BOOL )onlySelectionChanged {
132148 EnrichedInputTextView *textView = _input->textView ;
133149 NSRange selectedRange = textView.selectedRange ;
@@ -152,6 +168,16 @@ - (void)manageTypingAttributesWithOnlySelection:(BOOL)onlySelectionChanged {
152168
153169 [ParagraphAttributesUtils resetTypingAttributes: _input
154170 preservingAlignment: savedAlignment];
171+
172+ // newlines could have been made within a valid inline style, so
173+ // we want to preserve typingAttributes so they are correctly
174+ // acknowledged when typing
175+ if (paragraphRange.length == 1 ) {
176+ NSMutableDictionary *newAttrs = [textView.typingAttributes mutableCopy ];
177+ [self restoreInlineStylesPresentInRange: paragraphRange
178+ intoAttrs: newAttrs];
179+ textView.typingAttributes = newAttrs;
180+ }
155181 return ;
156182 }
157183 }
@@ -188,23 +214,10 @@ - (void)manageTypingAttributesWithOnlySelection:(BOOL)onlySelectionChanged {
188214 // getEntryIfPresent properly returns nullptr for styles that we don't want to
189215 // extend this way. Attributes from _removedTypingAttributes aren't added
190216 // because they were just removed.
191- for (StyleBase *style in _input->stylesDict .allValues ) {
192- if ([style isParagraph ])
193- continue ;
194- if ([_removedTypingAttributes containsObject: [style getKey ]])
195- continue ;
196-
197- AttributeEntry *entry = nullptr ;
198-
199- if (selectedRange.location > 0 ) {
200- entry =
201- [style getEntryIfPresent: NSMakeRange (selectedRange.location - 1 , 1 )];
202- }
203-
204- if (entry == nullptr )
205- continue ;
206-
207- newAttrs[entry.key] = entry.value ;
217+ if (selectedRange.location > 0 ) {
218+ [self restoreInlineStylesPresentInRange: NSMakeRange (
219+ selectedRange.location - 1 , 1 )
220+ intoAttrs: newAttrs];
208221 }
209222
210223 // Apply active styles to typing attributes only for styles that require it so
0 commit comments