Skip to content

Commit 540b211

Browse files
committed
fix(ios): ol indent resolution when applying typing attributes
1 parent 84963b1 commit 540b211

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

ios/styles/OrderedListStyle.mm

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ - (void)recalculateListsAroundEditedRange:(NSRange)range {
8888
}
8989

9090
// computes the shared marker-column indent for a list of the given item
91-
// count. The largest marker value equals the item count (numbering starts at 1);
92-
// if its width overflows the configured margin we expand to fit it
91+
// count. The largest marker value equals the item count (numbering starts
92+
// at 1); if its width overflows the configured margin we expand to fit it
9393
- (CGFloat)headIndentForItemCount:(NSInteger)itemCount {
9494
NSString *widestMarker =
9595
[NSString stringWithFormat:@"%d.", (int)MAX(itemCount, 1)];
@@ -141,13 +141,27 @@ - (void)applyStylingToTypingAttrs:(NSMutableDictionary *)attributes {
141141
if (pStyle == nil)
142142
return;
143143

144-
NSInteger itemCount = 0;
145-
[self contiguousOrderedListRangeContaining:self.host.textView.selectedRange
146-
itemCount:&itemCount];
147-
CGFloat listHeadIndent = [self headIndentForItemCount:itemCount];
144+
NSUInteger location = self.host.textView.selectedRange.location;
145+
NSUInteger length = self.host.textView.textStorage.length;
146+
147+
if (location < length) {
148+
// applying styling to typing attributes always happen after applying
149+
// the styles, so we can lookup the existing style for the indent
150+
NSParagraphStyle *existingStyle =
151+
[self.host.textView.textStorage attribute:NSParagraphStyleAttributeName
152+
atIndex:location
153+
effectiveRange:NULL];
154+
155+
if (existingStyle) {
156+
pStyle.headIndent = existingStyle.headIndent;
157+
pStyle.firstLineHeadIndent = existingStyle.firstLineHeadIndent;
158+
}
159+
} else {
160+
CGFloat fallbackIndent = [self headIndentForItemCount:1];
161+
pStyle.headIndent = fallbackIndent;
162+
pStyle.firstLineHeadIndent = fallbackIndent;
163+
}
148164

149-
pStyle.headIndent = listHeadIndent;
150-
pStyle.firstLineHeadIndent = listHeadIndent;
151165
attributes[NSParagraphStyleAttributeName] = pStyle;
152166
}
153167

0 commit comments

Comments
 (0)