Skip to content

Commit cd129a2

Browse files
fix: remove unnecessary color check
1 parent 1151599 commit cd129a2

1 file changed

Lines changed: 19 additions & 51 deletions

File tree

ios/styles/CodeBlockStyle.mm

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -180,35 +180,8 @@ - (BOOL)anyOccurence:(NSRange)range {
180180
];
181181
}
182182

183-
// gets ranges that aren't link, mention or inline code
184-
- (NSArray *)getProperColorRangesIn:(NSRange)range {
185-
LinkStyle *linkStyle = _input->stylesDict[@([LinkStyle getStyleType])];
186-
MentionStyle *mentionStyle = _input->stylesDict[@([MentionStyle getStyleType])];
187-
InlineCodeStyle *codeStyle = _input->stylesDict[@([InlineCodeStyle getStyleType])];
188-
189-
NSMutableArray *newRanges = [[NSMutableArray alloc] init];
190-
int lastRangeLocation = range.location;
191-
192-
for (int i = range.location; i < range.location + range.length; i++) {
193-
NSRange currentRange = NSMakeRange(i, 1);
194-
if ([linkStyle detectStyle:currentRange] || [mentionStyle detectStyle:currentRange] || [codeStyle detectStyle:currentRange]) {
195-
if (i - lastRangeLocation > 0) {
196-
[newRanges addObject:[NSValue valueWithRange:NSMakeRange(lastRangeLocation, i - lastRangeLocation)]];
197-
}
198-
lastRangeLocation = i+1;
199-
}
200-
}
201-
if (lastRangeLocation < range.location + range.length) {
202-
[newRanges addObject:[NSValue valueWithRange:NSMakeRange(lastRangeLocation, range.location + range.length - lastRangeLocation)]];
203-
}
204-
205-
return newRanges;
206-
}
207-
208-
// general checkup correcting codeBlock color
209-
// since links, mentions and inline code affects coloring, the checkup gets done only outside of them
210183
- (void)manageCodeBlockColor {
211-
if([[_input->config blockquoteColor] isEqualToColor:[_input->config primaryColor]]) {
184+
if([[_input->config codeBlockFgColor] isEqualToColor:[_input->config primaryColor]]) {
212185
return;
213186
}
214187

@@ -217,31 +190,26 @@ - (void)manageCodeBlockColor {
217190
NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView range:wholeRange];
218191
for(NSValue *pValue in paragraphs) {
219192
NSRange paragraphRange = [pValue rangeValue];
220-
NSArray *properRanges = [self getProperColorRangesIn:paragraphRange];
193+
BOOL selfDetected = [self detectStyle:paragraphRange];
221194

222-
for(NSValue *value in properRanges) {
223-
NSRange currRange = [value rangeValue];
224-
BOOL selfDetected = [self detectStyle:currRange];
225-
226-
[_input->textView.textStorage enumerateAttribute:NSForegroundColorAttributeName inRange:currRange options:0
227-
usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
228-
UIColor *newColor = nullptr;
229-
BOOL colorApplied = [(UIColor *)value isEqualToColor:[_input->config codeBlockFgColor]];
230-
231-
if(colorApplied && !selfDetected) {
232-
newColor = [_input->config primaryColor];
233-
} else if(!colorApplied && selfDetected) {
234-
newColor = [_input->config codeBlockFgColor];
235-
}
236-
237-
if(newColor != nullptr) {
238-
[_input->textView.textStorage addAttribute:NSForegroundColorAttributeName value:newColor range:currRange];
239-
[_input->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:newColor range:currRange];
240-
[_input->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:newColor range:currRange];
241-
}
195+
[_input->textView.textStorage enumerateAttribute:NSForegroundColorAttributeName inRange:paragraphRange options:0
196+
usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
197+
UIColor *newColor = nullptr;
198+
BOOL colorApplied = [(UIColor *)value isEqualToColor:[_input->config codeBlockFgColor]];
199+
200+
if(colorApplied && !selfDetected) {
201+
newColor = [_input->config primaryColor];
202+
} else if(!colorApplied && selfDetected) {
203+
newColor = [_input->config codeBlockFgColor];
242204
}
243-
];
244-
}
205+
206+
if(newColor != nullptr) {
207+
[_input->textView.textStorage addAttribute:NSForegroundColorAttributeName value:newColor range:range];
208+
[_input->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:newColor range:range];
209+
[_input->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:newColor range:range];
210+
}
211+
}
212+
];
245213
}
246214
}
247215

0 commit comments

Comments
 (0)