|
3 | 3 | #import "EditorManager.h" |
4 | 4 | #import "ReactNativeRichTextEditorView.h" |
5 | 5 | #import "StyleHeaders.h" |
| 6 | +#import "ParagraphsUtils.h" |
6 | 7 |
|
7 | 8 | @implementation NSLayoutManager (LayoutManagerExtension) |
8 | 9 |
|
@@ -77,42 +78,47 @@ - (void)my_drawBackgroundForGlyphRange:(NSRange)glyphRange atPoint:(CGPoint)orig |
77 | 78 | [allLists addObjectsFromArray:[olStyle findAllOccurences:editorRange]]; |
78 | 79 |
|
79 | 80 | for(StylePair *pair in allLists) { |
80 | | - NSRange paragraphRange = [typedEditor->textView.textStorage.string paragraphRangeForRange:[pair.rangeValue rangeValue]]; |
81 | | - NSRange paragraphGlyphRange = [self glyphRangeForCharacterRange:paragraphRange actualCharacterRange:nullptr]; |
82 | | - |
83 | 81 | NSParagraphStyle *pStyle = (NSParagraphStyle *)pair.styleValue; |
84 | 82 | NSDictionary *markerAttributes = @{ |
85 | 83 | NSFontAttributeName: [typedEditor->config primaryFont], |
86 | 84 | NSForegroundColorAttributeName: [typedEditor->config primaryColor] |
87 | 85 | }; |
88 | 86 |
|
89 | | - [self enumerateLineFragmentsForGlyphRange:paragraphGlyphRange |
90 | | - usingBlock:^(CGRect rect, CGRect usedRect, NSTextContainer *container, NSRange lineGlyphRange, BOOL *stop) { |
91 | | - NSString *marker = [self markerForList:pStyle.textLists.firstObject charIndex:[self characterIndexForGlyphAtIndex:lineGlyphRange.location] editor:typedEditor]; |
92 | | - |
93 | | - if(pStyle.textLists.firstObject.markerFormat == NSTextListMarkerDecimal) { |
94 | | - CGFloat gapWidth = [typedEditor->config orderedListGapWidth]; |
95 | | - CGFloat markerWidth = [marker sizeWithAttributes:markerAttributes].width; |
96 | | - CGFloat rightEdge = usedRect.origin.x - gapWidth; |
97 | | - CGFloat numberX = rightEdge - markerWidth; |
98 | | - |
99 | | - [marker drawAtPoint:CGPointMake(numberX, usedRect.origin.y + origin.y) withAttributes:markerAttributes]; |
100 | | - } else { |
101 | | - CGFloat gapWidth = [typedEditor->config unorderedListGapWidth]; |
102 | | - CGFloat bulletSize = [typedEditor->config unorderedListBulletSize]; |
103 | | - CGFloat bulletX = usedRect.origin.x - gapWidth - bulletSize; |
104 | | - CGFloat centerY = CGRectGetMidY(usedRect); |
| 87 | + NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:typedEditor->textView range:[pair.rangeValue rangeValue]]; |
| 88 | + |
| 89 | + for(NSValue *paragraph in paragraphs) { |
| 90 | + NSRange paragraphGlyphRange = [self glyphRangeForCharacterRange:[paragraph rangeValue] actualCharacterRange:nullptr]; |
| 91 | + |
| 92 | + [self enumerateLineFragmentsForGlyphRange:paragraphGlyphRange |
| 93 | + usingBlock:^(CGRect rect, CGRect usedRect, NSTextContainer *container, NSRange lineGlyphRange, BOOL *stop) { |
| 94 | + NSString *marker = [self markerForList:pStyle.textLists.firstObject charIndex:[self characterIndexForGlyphAtIndex:lineGlyphRange.location] editor:typedEditor]; |
105 | 95 |
|
106 | | - CGContextRef context = UIGraphicsGetCurrentContext(); |
107 | | - CGContextSaveGState(context); { |
108 | | - [[typedEditor->config unorderedListBulletColor] setFill]; |
109 | | - CGContextAddArc(context, bulletX, centerY, bulletSize/2, 0, 2 * M_PI, YES); |
110 | | - CGContextFillPath(context); |
| 96 | + if(pStyle.textLists.firstObject.markerFormat == NSTextListMarkerDecimal) { |
| 97 | + CGFloat gapWidth = [typedEditor->config orderedListGapWidth]; |
| 98 | + CGFloat markerWidth = [marker sizeWithAttributes:markerAttributes].width; |
| 99 | + CGFloat rightEdge = usedRect.origin.x - gapWidth; |
| 100 | + CGFloat numberX = rightEdge - markerWidth; |
| 101 | + |
| 102 | + [marker drawAtPoint:CGPointMake(numberX, usedRect.origin.y + origin.y) withAttributes:markerAttributes]; |
| 103 | + } else { |
| 104 | + CGFloat gapWidth = [typedEditor->config unorderedListGapWidth]; |
| 105 | + CGFloat bulletSize = [typedEditor->config unorderedListBulletSize]; |
| 106 | + CGFloat bulletX = usedRect.origin.x - gapWidth - bulletSize; |
| 107 | + CGFloat centerY = CGRectGetMidY(usedRect); |
| 108 | + |
| 109 | + CGContextRef context = UIGraphicsGetCurrentContext(); |
| 110 | + CGContextSaveGState(context); { |
| 111 | + [[typedEditor->config unorderedListBulletColor] setFill]; |
| 112 | + CGContextAddArc(context, bulletX, centerY, bulletSize/2, 0, 2 * M_PI, YES); |
| 113 | + CGContextFillPath(context); |
| 114 | + } |
| 115 | + CGContextRestoreGState(context); |
111 | 116 | } |
112 | | - CGContextRestoreGState(context); |
| 117 | + // only first line of a list gets its marker drawn |
| 118 | + *stop = YES; |
113 | 119 | } |
114 | | - } |
115 | | - ]; |
| 120 | + ]; |
| 121 | + } |
116 | 122 | } |
117 | 123 | } |
118 | 124 |
|
|
0 commit comments