File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments