Skip to content

Commit cef7707

Browse files
authored
Merge branch 'main' into @ksienkiewicz/fix-ios-typing-attributes-desync
2 parents 49ba596 + bbe2db4 commit cef7707

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

ios/utils/StyleUtils.mm

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,19 +229,28 @@ + (NSArray *)getPresentStyleTypesFrom:(NSArray *)types
229229
forHost:(id<EnrichedViewHost>)host {
230230
NSMutableArray<NSNumber *> *resultArray =
231231
[[NSMutableArray<NSNumber *> alloc] init];
232+
233+
// There might be a case where the given `range` doesn't have a conflicting
234+
// style, but it is present in typing attributes. In that case, run `detect:`
235+
// for good measure, since it considers typing attributes (unlike `any:`).
236+
NSRange selectedRange = host.textView.selectedRange;
237+
BOOL caretWithinRange = range.length >= 1 && selectedRange.length == 0 &&
238+
selectedRange.location >= range.location &&
239+
selectedRange.location <= NSMaxRange(range);
240+
232241
for (NSNumber *type in types) {
233242
StyleBase *style = host.stylesDict[type];
234243

235-
if (range.length >= 1) {
236-
if ([style any:range]) {
237-
[resultArray addObject:type];
238-
}
239-
} else {
240-
if ([style detect:range]) {
241-
[resultArray addObject:type];
242-
}
244+
BOOL present = range.length >= 1 ? [style any:range] : [style detect:range];
245+
if (!present && caretWithinRange) {
246+
present = [style detect:selectedRange];
247+
}
248+
249+
if (present) {
250+
[resultArray addObject:type];
243251
}
244252
}
253+
245254
return resultArray;
246255
}
247256

0 commit comments

Comments
 (0)