Skip to content
Open
Changes from 1 commit
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
26 changes: 18 additions & 8 deletions ios/utils/StyleUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,29 @@ + (NSArray *)getPresentStyleTypesFrom:(NSArray *)types
forHost:(id<EnrichedViewHost>)host {
NSMutableArray<NSNumber *> *resultArray =
[[NSMutableArray<NSNumber *> alloc] init];

// there might be a case where the given `range` doesn't have the
// present conflicting style, but it is present in typing attributes,
// so we run `detect:range` for good measure, as it analyzes typing
// attributes unlike `any:range`
Comment thread
Copilot marked this conversation as resolved.
Outdated
NSRange selectedRange = host.textView.selectedRange;
BOOL caretWithinRange = range.length >= 1 && selectedRange.length == 0 &&
selectedRange.location >= range.location &&
selectedRange.location <= NSMaxRange(range);

for (NSNumber *type in types) {
StyleBase *style = host.stylesDict[type];

if (range.length >= 1) {
if ([style any:range]) {
[resultArray addObject:type];
}
} else {
if ([style detect:range]) {
[resultArray addObject:type];
}
BOOL present = range.length >= 1 ? [style any:range] : [style detect:range];
if (!present && caretWithinRange) {
present = [style detect:selectedRange];
}

if (present) {
[resultArray addObject:type];
}
}

return resultArray;
}

Expand Down
Loading