File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1502,11 +1502,12 @@ - (void)setStyle:(NSString *)styleJSON {
15021502 NSData *jsonData = [styleJSON dataUsingEncoding: NSUTF8StringEncoding];
15031503 if (jsonData == nil )
15041504 return ;
1505- NSDictionary *dict = [NSJSONSerialization JSONObjectWithData: jsonData
1506- options: 0
1507- error: nil ];
1508- if (dict == nil )
1505+ id parsed = [NSJSONSerialization JSONObjectWithData: jsonData
1506+ options: 0
1507+ error: nil ];
1508+ if (![parsed isKindOfClass: [ NSDictionary class ]] )
15091509 return ;
1510+ NSDictionary *dict = (NSDictionary *)parsed;
15101511
15111512 NSRange selectedRange = textView.selectedRange ;
15121513 CustomStyle *customStyleClass =
@@ -1962,8 +1963,10 @@ - (bool)textView:(UITextView *)textView
19621963 replacementText : (NSString *)text {
19631964 // Capture the attributes at range.location that are being replaced
19641965 // (autocorrect / predictive) so didProcessEditing: can re-stamp them onto the
1965- // replacement.
1966- if (range.length > 0 ) {
1966+ // replacement. Skip pure deletions (text.length == 0) — there is no incoming
1967+ // text to receive attributes, and capturing here would cause the deleted
1968+ // character's CustomStyleData to be re-stamped onto the widened editedRange.
1969+ if (range.length > 0 && text.length > 0 ) {
19671970 _capturedAttributesBeforeChange =
19681971 [textView.textStorage attributesAtIndex: range.location
19691972 effectiveRange: NULL ];
You can’t perform that action at this time.
0 commit comments