@@ -229,19 +229,29 @@ + (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 the
234+ // present conflicting style, but it is present in typing attributes,
235+ // so we run `detect:range` for good measure, as it analyzes typing
236+ // attributes unlike `any:range`
237+ NSRange selectedRange = host.textView .selectedRange ;
238+ BOOL caretWithinRange = range.length >= 1 && selectedRange.length == 0 &&
239+ selectedRange.location >= range.location &&
240+ selectedRange.location <= NSMaxRange (range);
241+
232242 for (NSNumber *type in types) {
233243 StyleBase *style = host.stylesDict [type];
234244
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- }
245+ BOOL present = range.length >= 1 ? [style any: range] : [style detect: range];
246+ if (!present && caretWithinRange) {
247+ present = [style detect: selectedRange];
248+ }
249+
250+ if (present) {
251+ [resultArray addObject: type];
243252 }
244253 }
254+
245255 return resultArray;
246256}
247257
0 commit comments