From cea191020b9390fd014aca12a1e90c0156218825 Mon Sep 17 00:00:00 2001 From: Krystian Sienkiewicz Date: Thu, 13 Aug 2026 12:28:59 +0200 Subject: [PATCH 1/2] fix: conflicting styles in typing attributes not correctly detected --- ios/utils/StyleUtils.mm | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/ios/utils/StyleUtils.mm b/ios/utils/StyleUtils.mm index 838269221..646f3806d 100644 --- a/ios/utils/StyleUtils.mm +++ b/ios/utils/StyleUtils.mm @@ -229,19 +229,29 @@ + (NSArray *)getPresentStyleTypesFrom:(NSArray *)types forHost:(id)host { NSMutableArray *resultArray = [[NSMutableArray 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` + 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; } From 671e0d7b658c87ff3aab8ca752e96ef157f7118a Mon Sep 17 00:00:00 2001 From: Krystian Sienkiewicz <146986839+hejsztynx@users.noreply.github.com> Date: Thu, 13 Aug 2026 14:34:02 +0200 Subject: [PATCH 2/2] refactor: comment tweak Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- ios/utils/StyleUtils.mm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ios/utils/StyleUtils.mm b/ios/utils/StyleUtils.mm index 646f3806d..167a32df5 100644 --- a/ios/utils/StyleUtils.mm +++ b/ios/utils/StyleUtils.mm @@ -230,10 +230,9 @@ + (NSArray *)getPresentStyleTypesFrom:(NSArray *)types NSMutableArray *resultArray = [[NSMutableArray 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` + // There might be a case where the given `range` doesn't have a conflicting + // style, but it is present in typing attributes. In that case, run `detect:` + // for good measure, since it considers typing attributes (unlike `any:`). NSRange selectedRange = host.textView.selectedRange; BOOL caretWithinRange = range.length >= 1 && selectedRange.length == 0 && selectedRange.location >= range.location &&