@@ -55,19 +55,30 @@ - (NSString *)parseToHtmlFromRange:(NSRange)range {
5555 }
5656 }
5757
58- // Handle valued styles changes
5958 UIColor *currentColor = nil ;
60-
59+
6160 if ([currentActiveStyles containsObject: @(Colored)]) {
6261 ColorStyle *colorStyle = _input->stylesDict [@(Colored)];
6362 currentColor = [colorStyle getColorAt: currentRange.location];
64- if (previousColor && ![currentColor isEqual: previousColor]) {
65- // Treat as end of previous color and start of new
66- [currentActiveStyles removeObject: @(Colored)];
67- currentActiveStylesBeginning[@(Colored)] = [NSNumber numberWithInt: i];
63+ // If the end of one color overlaps exactly with the start of the next
64+ // the previous font tag should be closed and a new one opened using the new color.
65+ if (previousColor && ![currentColor isEqual: previousColor]) {
66+ NSString *closeTag = [self tagContentForStyle: @(Colored)
67+ openingTag: NO
68+ location: currentRange.location];
69+ [result appendFormat: @" </%@ >" , closeTag];
70+ NSString *openTag = [self tagContentForStyle: @(Colored)
71+ openingTag: YES
72+ location: currentRange.location];
73+ [result appendFormat: @" <%@ >" , openTag];
74+ NSString *currentCharacterStr = [_input->textView.textStorage.string substringWithRange: currentRange];
75+ [result appendString: currentCharacterStr];
76+ previousColor = currentColor;
77+ [currentActiveStyles addObject: @(Colored)];
78+ continue ;
6879 }
6980 }
70-
81+
7182 NSString *currentCharacterStr = [_input->textView.textStorage.string substringWithRange: currentRange];
7283 unichar currentCharacterChar = [_input->textView.textStorage.string characterAtIndex: currentRange.location];
7384
0 commit comments