Skip to content

Commit 3ae7cb0

Browse files
committed
fix: one more clarification/improvement
1 parent 3034f8d commit 3ae7cb0

1 file changed

Lines changed: 16 additions & 34 deletions

File tree

ios/utils/ParagraphAttributesUtils.mm

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,42 +34,24 @@ + (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text i
3434

3535
NSRange nonNewlineRange = [(NSValue *)paragraphs.firstObject rangeValue];
3636

37-
// if the backspace removes the whole content of a paragraph, we remove the typing attributes
38-
if(NSEqualRanges(nonNewlineRange, range)) {
39-
40-
// edge case with lists and blockquotes:
41-
// for some reason, removing all characters from a list point that is: both the first point of a list and is the last thing in the input, doesn't preserve typing attributes
42-
// so we manually remove the characters and reapply attribtues for zero width space to appear there
43-
// otherwise (there still is list or quote) we don't want no actions because attributes are properly preserved and zero width space appears
44-
if([ulStyle detectStyle:paragraphRange]) {
45-
if(NSMaxRange(nonNewlineRange) == typedInput->textView.textStorage.string.length) {
46-
// manually remove the characters
47-
[TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr input:typedInput withSelection:YES];
48-
// add atributes again
49-
[ulStyle addAttributes:NSMakeRange(range.location, 0)];
50-
return YES;
51-
}
52-
return NO;
37+
// if the backspace removes the whole content of a paragraph (possibly more but has to start where the paragraph starts), we remove the typing attributes
38+
if(range.location == nonNewlineRange.location && range.length >= nonNewlineRange.length) {
39+
// for lists and quotes we want to remove the characters but keep attribtues so that a zero width space appears here
40+
// so we do the removing manually and reapply attributes
41+
if([ulStyle detectStyle:nonNewlineRange]) {
42+
[TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr input:typedInput withSelection:YES];
43+
[ulStyle addAttributes:NSMakeRange(range.location, 0)];
44+
return YES;
5345
}
54-
if([olStyle detectStyle:paragraphRange]) {
55-
if(NSMaxRange(nonNewlineRange) == typedInput->textView.textStorage.string.length) {
56-
// manually remove the characters
57-
[TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr input:typedInput withSelection:YES];
58-
// add atributes again
59-
[olStyle addAttributes:NSMakeRange(range.location, 0)];
60-
return YES;
61-
}
62-
return NO;
46+
if([olStyle detectStyle:nonNewlineRange]) {
47+
[TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr input:typedInput withSelection:YES];
48+
[olStyle addAttributes:NSMakeRange(range.location, 0)];
49+
return YES;
6350
}
64-
if([bqStyle detectStyle:paragraphRange]) {
65-
if(NSMaxRange(nonNewlineRange) == typedInput->textView.textStorage.string.length) {
66-
// manually remove the characters
67-
[TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr input:typedInput withSelection:YES];
68-
// add atributes again
69-
[bqStyle addAttributes:NSMakeRange(range.location, 0)];
70-
return YES;
71-
}
72-
return NO;
51+
if([bqStyle detectStyle:nonNewlineRange]) {
52+
[TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr input:typedInput withSelection:YES];
53+
[bqStyle addAttributes:NSMakeRange(range.location, 0)];
54+
return YES;
7355
}
7456

7557
// do the replacement manually

0 commit comments

Comments
 (0)