@@ -60,19 +60,30 @@ - (NSString *)parseToHtmlFromRange:(NSRange)range {
6060 }
6161 }
6262
63- // Handle valued styles changes
6463 UIColor *currentColor = nil ;
65-
64+
6665 if ([currentActiveStyles containsObject: @(Colored)]) {
6766 ColorStyle *colorStyle = _input->stylesDict [@(Colored)];
6867 currentColor = [colorStyle getColorAt: currentRange.location];
69- if (previousColor && ![currentColor isEqual: previousColor]) {
70- // Treat as end of previous color and start of new
71- [currentActiveStyles removeObject: @(Colored)];
72- currentActiveStylesBeginning[@(Colored)] = [NSNumber numberWithInt: i];
68+ // If the end of one color overlaps exactly with the start of the next
69+ // the previous font tag should be closed and a new one opened using the new color.
70+ if (previousColor && ![currentColor isEqual: previousColor]) {
71+ NSString *closeTag = [self tagContentForStyle: @(Colored)
72+ openingTag: NO
73+ location: currentRange.location];
74+ [result appendFormat: @" </%@ >" , closeTag];
75+ NSString *openTag = [self tagContentForStyle: @(Colored)
76+ openingTag: YES
77+ location: currentRange.location];
78+ [result appendFormat: @" <%@ >" , openTag];
79+ NSString *currentCharacterStr = [_input->textView.textStorage.string substringWithRange: currentRange];
80+ [result appendString: currentCharacterStr];
81+ previousColor = currentColor;
82+ [currentActiveStyles addObject: @(Colored)];
83+ continue ;
7384 }
7485 }
75-
86+
7687 NSString *currentCharacterStr = [_input->textView.textStorage.string substringWithRange: currentRange];
7788 unichar currentCharacterChar = [_input->textView.textStorage.string characterAtIndex: currentRange.location];
7889
0 commit comments