Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 30 additions & 17 deletions ios/inputAttributesManager/InputAttributesManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Comment thread
szydlovsky marked this conversation as resolved.
NSMutableDictionary *newAttrs = [textView.typingAttributes mutableCopy];
[self restoreInlineStylesPresentInRange:paragraphRange
intoAttrs:newAttrs];
textView.typingAttributes = newAttrs;
}
return;
}
}
Expand Down Expand Up @@ -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
Expand Down
Loading