Skip to content

Commit c34015d

Browse files
authored
Merge branch 'main' into @ksienkiewicz/fix-ios-cjk-italics
2 parents 0a64ac7 + 7fa3793 commit c34015d

1 file changed

Lines changed: 30 additions & 17 deletions

File tree

ios/inputAttributesManager/InputAttributesManager.mm

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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
_recentOnlySelectionStatus = onlySelectionChanged;
133149
EnrichedInputTextView *textView = _input->textView;
@@ -153,6 +169,16 @@ - (void)manageTypingAttributesWithOnlySelection:(BOOL)onlySelectionChanged {
153169

154170
[ParagraphAttributesUtils resetTypingAttributes:_input
155171
preservingAlignment:savedAlignment];
172+
173+
// newlines could have been made within a valid inline style, so
174+
// we want to preserve typingAttributes so they are correctly
175+
// acknowledged when typing
176+
if (paragraphRange.length == 1) {
177+
NSMutableDictionary *newAttrs = [textView.typingAttributes mutableCopy];
178+
[self restoreInlineStylesPresentInRange:paragraphRange
179+
intoAttrs:newAttrs];
180+
textView.typingAttributes = newAttrs;
181+
}
156182
return;
157183
}
158184
}
@@ -189,23 +215,10 @@ - (void)manageTypingAttributesWithOnlySelection:(BOOL)onlySelectionChanged {
189215
// getEntryIfPresent properly returns nullptr for styles that we don't want to
190216
// extend this way. Attributes from _removedTypingAttributes aren't added
191217
// because they were just removed.
192-
for (StyleBase *style in _input->stylesDict.allValues) {
193-
if ([style isParagraph])
194-
continue;
195-
if ([_removedTypingAttributes containsObject:[style getKey]])
196-
continue;
197-
198-
AttributeEntry *entry = nullptr;
199-
200-
if (selectedRange.location > 0) {
201-
entry =
202-
[style getEntryIfPresent:NSMakeRange(selectedRange.location - 1, 1)];
203-
}
204-
205-
if (entry == nullptr)
206-
continue;
207-
208-
newAttrs[entry.key] = entry.value;
218+
if (selectedRange.location > 0) {
219+
[self restoreInlineStylesPresentInRange:NSMakeRange(
220+
selectedRange.location - 1, 1)
221+
intoAttrs:newAttrs];
209222
}
210223

211224
// Apply active styles to typing attributes only for styles that require it so

0 commit comments

Comments
 (0)