Skip to content

Commit 3034f8d

Browse files
committed
fix: one more strange edge case
1 parent b2de8e2 commit 3034f8d

2 files changed

Lines changed: 37 additions & 6 deletions

File tree

ios/utils/OccurenceUtils.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ + (BOOL)detect
4747
NSRange attrRange = NSMakeRange(0, 0);
4848
attrValue = [input->textView.textStorage attribute:key atIndex:index effectiveRange:&attrRange];
4949
}
50-
return condition(attrValue, NSMakeRange(index, 0));
50+
return condition(attrValue, detectionRange);
5151
}
5252

5353
+ (BOOL)detectMultiple

ios/utils/ParagraphAttributesUtils.mm

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ + (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text i
2727
// find a non-newline range of the paragraph
2828
NSRange paragraphRange = [typedInput->textView.textStorage.string paragraphRangeForRange:range];
2929

30-
// for lists and quotes we don't want that behavior; we want zero width spaces to appear there
31-
if([ulStyle detectStyle:paragraphRange] || [olStyle detectStyle:paragraphRange] || [bqStyle detectStyle:paragraphRange]) {
32-
return NO;
33-
}
34-
3530
NSArray *paragraphs = [ParagraphsUtils getNonNewlineRangesIn:typedInput->textView range:paragraphRange];
3631
if(paragraphs.count == 0) {
3732
return NO;
@@ -41,6 +36,42 @@ + (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text i
4136

4237
// if the backspace removes the whole content of a paragraph, we remove the typing attributes
4338
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;
53+
}
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;
63+
}
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;
73+
}
74+
4475
// do the replacement manually
4576
[TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr input:typedInput withSelection:YES];
4677
// reset typing attribtues

0 commit comments

Comments
 (0)