Skip to content

Commit d196f44

Browse files
committed
fix(ios): correct typingattributes on styling
1 parent b1643b8 commit d196f44

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

ios/styles/OrderedListStyle.mm

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,20 @@ - (void)applyStylingToTypingAttrs:(NSMutableDictionary *)attributes {
146146
NSUInteger location = self.host.textView.selectedRange.location;
147147
NSUInteger length = self.host.textView.textStorage.length;
148148

149-
if (location < length) {
149+
NSParagraphStyle *existingStyle = nil;
150+
if (length > 0) {
150151
// applying styling to typing attributes always happen after applying
151152
// the styles, so we can lookup the existing style for the indent
152-
NSParagraphStyle *existingStyle =
153+
NSUInteger lookupLocation = MIN(location, length - 1);
154+
existingStyle =
153155
[self.host.textView.textStorage attribute:NSParagraphStyleAttributeName
154-
atIndex:location
156+
atIndex:lookupLocation
155157
effectiveRange:NULL];
158+
}
156159

157-
if (existingStyle) {
158-
pStyle.headIndent = existingStyle.headIndent;
159-
pStyle.firstLineHeadIndent = existingStyle.firstLineHeadIndent;
160-
}
160+
if (existingStyle) {
161+
pStyle.headIndent = existingStyle.headIndent;
162+
pStyle.firstLineHeadIndent = existingStyle.firstLineHeadIndent;
161163
} else {
162164
CGFloat fallbackIndent = [self headIndentForItemCount:1];
163165
pStyle.headIndent = fallbackIndent;

0 commit comments

Comments
 (0)