Skip to content

Commit c60ddba

Browse files
fix(iOS): drawing lists in Japanese (#729)
# Summary Fixes: #728 This PR: - preserves list markers when composing Japanese characters in an empty list item by applying the liststyle to the typing attributes - fixes drawing checkbox when inline code active ## Test Plan 1. Run reproduction steps from issue: #728. The problem should be resolved 2. Toggle checkbox and inline code write something then toggle off inline code and write something -> checkbox should not change its size ## Screenshots / Videos Before: https://github.com/user-attachments/assets/3d39d424-1ba3-4e62-89a0-3c2abc0416a6 After: https://github.com/user-attachments/assets/0fc61de7-3561-43ab-9313-e3d5858f4c23 ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | Android | ❌ | | Web | ❌ | ## Checklist - [x] E2E tests are passing - [ ] Required E2E tests have been added (if applicable)
1 parent 3e82fe6 commit c60ddba

6 files changed

Lines changed: 123 additions & 16 deletions

File tree

ios/extensions/LayoutManagerExtension.mm

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ - (void)drawLists:(id<EnrichedViewHost>)host
264264
NSForegroundColorAttributeName : [host.config orderedListMarkerColor]
265265
};
266266
CGFloat indent = pStyle.firstLineHeadIndent;
267+
UIFont *referenceFont = [host.config primaryFont];
267268

268269
NSArray *paragraphs =
269270
[RangeUtils getSeparateParagraphsRangesIn:host.textView
@@ -283,13 +284,9 @@ - (void)drawLists:(id<EnrichedViewHost>)host
283284
NSUInteger charIdx =
284285
[self characterIndexForGlyphAtIndex:
285286
lineGlyphRange.location];
286-
UIFont *font = [host.textView.textStorage
287-
attribute:NSFontAttributeName
288-
atIndex:charIdx
289-
effectiveRange:nil];
290-
CGRect textUsedRect =
291-
[self getTextAlignedUsedRect:usedRect
292-
font:font];
287+
CGRect textUsedRect = [self
288+
getTextAlignedUsedRect:usedRect
289+
font:referenceFont];
293290

294291
for (NSTextList *list in pStyle
295292
.textLists) {

ios/styles/BlockQuoteStyle.mm

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ - (BOOL)needsZWS {
2020
return YES;
2121
}
2222

23+
- (CGFloat)headIndent {
24+
return [self.host.config blockquoteBorderWidth] +
25+
[self.host.config blockquoteGapWidth];
26+
}
27+
2328
- (void)applyStyling:(NSRange)range {
24-
CGFloat indent = [self.host.config blockquoteBorderWidth] +
25-
[self.host.config blockquoteGapWidth];
29+
CGFloat indent = [self headIndent];
2630
[self.host.textView.textStorage
2731
enumerateAttribute:NSParagraphStyleAttributeName
2832
inRange:range
@@ -51,4 +55,26 @@ - (void)applyStyling:(NSRange)range {
5155
range:range];
5256
}
5357

58+
- (BOOL)appliesStylingToTyping {
59+
return YES;
60+
}
61+
62+
- (void)applyStylingToTypingAttrs:(NSMutableDictionary *)attributes {
63+
NSMutableParagraphStyle *pStyle =
64+
[attributes[NSParagraphStyleAttributeName] mutableCopy];
65+
if (pStyle == nil)
66+
return;
67+
CGFloat indent = [self headIndent];
68+
pStyle.headIndent = indent;
69+
pStyle.firstLineHeadIndent = indent;
70+
attributes[NSParagraphStyleAttributeName] = pStyle;
71+
72+
UIColor *bqColor = [self.host.config blockquoteColor];
73+
if (bqColor != nil) {
74+
attributes[NSForegroundColorAttributeName] = bqColor;
75+
attributes[NSUnderlineColorAttributeName] = bqColor;
76+
attributes[NSStrikethroughColorAttributeName] = bqColor;
77+
}
78+
}
79+
5480
@end

ios/styles/CheckboxListStyle.mm

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,19 @@ - (BOOL)needsZWS {
2626
return YES;
2727
}
2828

29+
- (CGFloat)headIndent {
30+
return [self.host.config checkboxListMarginLeft] +
31+
[self.host.config checkboxListGapWidth] +
32+
[self.host.config checkboxListBoxSize];
33+
}
34+
35+
- (CGFloat)calculateMinimumLineHeight:(CGFloat)currentLineHeight {
36+
CGFloat boxSize = [self.host.config checkboxListBoxSize];
37+
return MAX(currentLineHeight, boxSize);
38+
}
39+
2940
- (void)applyStyling:(NSRange)range {
30-
CGFloat listHeadIndent = [self.host.config checkboxListMarginLeft] +
31-
[self.host.config checkboxListGapWidth] +
32-
[self.host.config checkboxListBoxSize];
41+
CGFloat listHeadIndent = [self headIndent];
3342

3443
[self.host.textView.textStorage
3544
enumerateAttribute:NSParagraphStyleAttributeName
@@ -41,13 +50,32 @@ - (void)applyStyling:(NSRange)range {
4150
[(NSParagraphStyle *)value mutableCopy];
4251
pStyle.headIndent = listHeadIndent;
4352
pStyle.firstLineHeadIndent = listHeadIndent;
53+
pStyle.minimumLineHeight =
54+
[self calculateMinimumLineHeight:pStyle.minimumLineHeight];
4455
[self.host.textView.textStorage
4556
addAttribute:NSParagraphStyleAttributeName
4657
value:pStyle
4758
range:range];
4859
}];
4960
}
5061

62+
- (BOOL)appliesStylingToTyping {
63+
return YES;
64+
}
65+
66+
- (void)applyStylingToTypingAttrs:(NSMutableDictionary *)attributes {
67+
NSMutableParagraphStyle *pStyle =
68+
[attributes[NSParagraphStyleAttributeName] mutableCopy];
69+
if (pStyle == nil)
70+
return;
71+
CGFloat indent = [self headIndent];
72+
pStyle.headIndent = indent;
73+
pStyle.firstLineHeadIndent = indent;
74+
pStyle.minimumLineHeight =
75+
[self calculateMinimumLineHeight:pStyle.minimumLineHeight];
76+
attributes[NSParagraphStyleAttributeName] = pStyle;
77+
}
78+
5179
- (BOOL)styleCondition:(id)value range:(NSRange)range {
5280
NSParagraphStyle *pStyle = (NSParagraphStyle *)value;
5381
if (pStyle == nil)

ios/styles/CodeBlockStyle.mm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,22 @@ - (void)applyStyling:(NSRange)range {
4646
range:range];
4747
}
4848

49+
- (BOOL)appliesStylingToTyping {
50+
return YES;
51+
}
52+
53+
- (void)applyStylingToTypingAttrs:(NSMutableDictionary *)attributes {
54+
UIFont *currentFont =
55+
attributes[NSFontAttributeName] ?: [self.host.config primaryFont];
56+
UIFont *monoFont = [[[self.host.config monospacedFont]
57+
withFontTraits:currentFont] setSize:currentFont.pointSize];
58+
if (monoFont != nil) {
59+
attributes[NSFontAttributeName] = monoFont;
60+
}
61+
UIColor *fgColor = [self.host.config codeBlockFgColor];
62+
if (fgColor != nil) {
63+
attributes[NSForegroundColorAttributeName] = fgColor;
64+
}
65+
}
66+
4967
@end

ios/styles/OrderedListStyle.mm

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ - (BOOL)needsZWS {
2222
return YES;
2323
}
2424

25+
- (CGFloat)headIndent {
26+
return [self.host.config orderedListMarginLeft] +
27+
[self.host.config orderedListGapWidth];
28+
}
29+
2530
- (void)applyStyling:(NSRange)range {
2631
// lists are drawn manually
2732
// margin before marker + gap between marker and paragraph
28-
CGFloat listHeadIndent = [self.host.config orderedListMarginLeft] +
29-
[self.host.config orderedListGapWidth];
33+
CGFloat listHeadIndent = [self headIndent];
3034

3135
[self.host.textView.textStorage
3236
enumerateAttribute:NSParagraphStyleAttributeName
@@ -45,4 +49,19 @@ - (void)applyStyling:(NSRange)range {
4549
}];
4650
}
4751

52+
- (BOOL)appliesStylingToTyping {
53+
return YES;
54+
}
55+
56+
- (void)applyStylingToTypingAttrs:(NSMutableDictionary *)attributes {
57+
NSMutableParagraphStyle *pStyle =
58+
[attributes[NSParagraphStyleAttributeName] mutableCopy];
59+
if (pStyle == nil)
60+
return;
61+
CGFloat indent = [self headIndent];
62+
pStyle.headIndent = indent;
63+
pStyle.firstLineHeadIndent = indent;
64+
attributes[NSParagraphStyleAttributeName] = pStyle;
65+
}
66+
4867
@end

ios/styles/UnorderedListStyle.mm

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ - (BOOL)needsZWS {
2222
return YES;
2323
}
2424

25+
- (CGFloat)headIndent {
26+
return [self.host.config unorderedListMarginLeft] +
27+
[self.host.config unorderedListGapWidth];
28+
}
29+
2530
- (void)applyStyling:(NSRange)range {
2631
// lists are drawn manually
2732
// margin before bullet + gap between bullet and paragraph
28-
CGFloat listHeadIndent = [self.host.config unorderedListMarginLeft] +
29-
[self.host.config unorderedListGapWidth];
33+
CGFloat listHeadIndent = [self headIndent];
3034

3135
[self.host.textView.textStorage
3236
enumerateAttribute:NSParagraphStyleAttributeName
@@ -45,4 +49,19 @@ - (void)applyStyling:(NSRange)range {
4549
}];
4650
}
4751

52+
- (BOOL)appliesStylingToTyping {
53+
return YES;
54+
}
55+
56+
- (void)applyStylingToTypingAttrs:(NSMutableDictionary *)attributes {
57+
NSMutableParagraphStyle *pStyle =
58+
[attributes[NSParagraphStyleAttributeName] mutableCopy];
59+
if (pStyle == nil)
60+
return;
61+
CGFloat indent = [self headIndent];
62+
pStyle.headIndent = indent;
63+
pStyle.firstLineHeadIndent = indent;
64+
attributes[NSParagraphStyleAttributeName] = pStyle;
65+
}
66+
4867
@end

0 commit comments

Comments
 (0)