Skip to content

Commit bbe2db4

Browse files
hejsztynxCopilot
andauthored
fix(ios): conflicting styles in typing attributes not correctly detected (#770)
# Summary There was a bug which you can see in the attached video below. The issue was that when applying `codeblock` style, we apply it to a whole paragraph, and during this process we look for conflicting styles in the paragraph's range. The problem is, we don't look at current typing attributes for conflicting styles, as there is a case when: - there is no conflicting style in the given paragraph range - there is a conflicting style in typing attributes The implemented fix is minimal, as I didn't want to tamper with current logic - that's why we catch that specific case with an `if`. I've run the e2e tests, everything passes. ## Test Plan Reproduce the bug from the attached video, play around with toggling different styles. ## Screenshots / Videos Before: https://github.com/user-attachments/assets/109cfc99-2614-422c-9f7d-3b0c058e08fe After: https://github.com/user-attachments/assets/c10d6d2c-ca1e-432b-a7ae-268bced9c465 ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | Android | ❌ | | Web | ❌ | ## Checklist - [x] E2E tests are passing - [ ] Required E2E tests have been added (if applicable) --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 505a055 commit bbe2db4

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)