File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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;
You can’t perform that action at this time.
0 commit comments