Skip to content

Commit 7fa3793

Browse files
authored
fix(ios): synced newline typing attributes with actual textStorage attributes (#775)
# Summary Managing typing attributes was implemented in such way that when you moved the cursor to an empty line, the typing attributes got reset. This was to prevent picking up the style from the previous line, but it was done unconditionally. That caused the typingAttributes to be reset even though a style is already present in the newline and valid. ## Test Plan Experiment around, follow the test flow from the attached videos ## Screenshots / Videos Before: https://github.com/user-attachments/assets/e0670f31-abf8-4953-b9e9-c97f7f50c1ef After: https://github.com/user-attachments/assets/2f9df226-4f90-451e-a611-4b501df50697 ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | Android | ❌ | | Web | ❌ | ## Checklist - [ ] E2E tests are passing - [ ] Required E2E tests have been added (if applicable)
1 parent 08eed0e commit 7fa3793

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
@@ -130,6 +130,22 @@ - (void)handleDirtyRangesStyling {
130130
[_dirtyRanges removeAllObjects];
131131
}
132132

133+
- (void)restoreInlineStylesPresentInRange:(NSRange)range
134+
intoAttrs:(NSMutableDictionary *)attrs {
135+
for (StyleBase *style in _input->stylesDict.allValues) {
136+
if ([style isParagraph])
137+
continue;
138+
if ([_removedTypingAttributes containsObject:[style getKey]])
139+
continue;
140+
141+
AttributeEntry *entry = [style getEntryIfPresent:range];
142+
if (entry == nullptr)
143+
continue;
144+
145+
attrs[entry.key] = entry.value;
146+
}
147+
}
148+
133149
- (void)manageTypingAttributesWithOnlySelection:(BOOL)onlySelectionChanged {
134150
_recentOnlySelectionStatus = onlySelectionChanged;
135151
EnrichedInputTextView *textView = _input->textView;
@@ -155,6 +171,16 @@ - (void)manageTypingAttributesWithOnlySelection:(BOOL)onlySelectionChanged {
155171

156172
[ParagraphAttributesUtils resetTypingAttributes:_input
157173
preservingAlignment:savedAlignment];
174+
175+
// newlines could have been made within a valid inline style, so
176+
// we want to preserve typingAttributes so they are correctly
177+
// acknowledged when typing
178+
if (paragraphRange.length == 1) {
179+
NSMutableDictionary *newAttrs = [textView.typingAttributes mutableCopy];
180+
[self restoreInlineStylesPresentInRange:paragraphRange
181+
intoAttrs:newAttrs];
182+
textView.typingAttributes = newAttrs;
183+
}
158184
return;
159185
}
160186
}
@@ -191,23 +217,10 @@ - (void)manageTypingAttributesWithOnlySelection:(BOOL)onlySelectionChanged {
191217
// getEntryIfPresent properly returns nullptr for styles that we don't want to
192218
// extend this way. Attributes from _removedTypingAttributes aren't added
193219
// because they were just removed.
194-
for (StyleBase *style in _input->stylesDict.allValues) {
195-
if ([style isParagraph])
196-
continue;
197-
if ([_removedTypingAttributes containsObject:[style getKey]])
198-
continue;
199-
200-
AttributeEntry *entry = nullptr;
201-
202-
if (selectedRange.location > 0) {
203-
entry =
204-
[style getEntryIfPresent:NSMakeRange(selectedRange.location - 1, 1)];
205-
}
206-
207-
if (entry == nullptr)
208-
continue;
209-
210-
newAttrs[entry.key] = entry.value;
220+
if (selectedRange.location > 0) {
221+
[self restoreInlineStylesPresentInRange:NSMakeRange(
222+
selectedRange.location - 1, 1)
223+
intoAttrs:newAttrs];
211224
}
212225

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

0 commit comments

Comments
 (0)