Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ios/styles/BlockQuoteStyle.mm
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ - (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text {
}
NSRange nonNewlineRange = [nonNewlineVal rangeValue];
if(NSEqualRanges(range, nonNewlineRange)) {
[self removeAttributes:range];
[TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr input:_input withSelection:YES];
[self removeAttributes:NSMakeRange(range.location, 0)];
return YES;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ios/styles/OrderedListStyle.mm
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ - (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text {
}
NSRange nonNewlineRange = [nonNewlineVal rangeValue];
if(NSEqualRanges(range, nonNewlineRange)) {
[self removeAttributes:range];
[TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr input:_input withSelection:YES];
[self removeAttributes:NSMakeRange(range.location, 0)];
return YES;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ios/styles/UnorderedListStyle.mm
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ - (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text {
}
NSRange nonNewlineRange = [nonNewlineVal rangeValue];
if(NSEqualRanges(range, nonNewlineRange)) {
[self removeAttributes:range];
[TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr input:_input withSelection:YES];
[self removeAttributes:NSMakeRange(range.location, 0)];
return YES;
}
}
Expand Down
20 changes: 14 additions & 6 deletions ios/utils/ZeroWidthSpaceUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,23 @@ + (void)removeSpacesIfNeededinInput:(EnrichedTextInputView *)input {

// do the removing
NSInteger offset = 0;
NSInteger postRemoveOffset = 0;
NSInteger postRemoveLocationOffset = 0;
NSInteger postRemoveLengthOffset = 0;
for(NSNumber *index in indexesToBeRemoved) {
NSRange replaceRange = NSMakeRange([index integerValue] + offset, 1);
[TextInsertionUtils replaceText:@"" at:replaceRange additionalAttributes:nullptr input:input withSelection:NO];
offset -= 1;
if([index integerValue] < preRemoveSelection.location) {
postRemoveOffset -= 1;
postRemoveLocationOffset -= 1;
}
if([index integerValue] >= preRemoveSelection.location && [index integerValue] < NSMaxRange(preRemoveSelection)) {
postRemoveLengthOffset -= 1;
}
}

// fix the selection if needed
if([input->textView isFirstResponder]) {
input->textView.selectedRange = NSMakeRange(preRemoveSelection.location + postRemoveOffset, preRemoveSelection.length);
input->textView.selectedRange = NSMakeRange(preRemoveSelection.location + postRemoveLocationOffset, preRemoveSelection.length + postRemoveLengthOffset);
}
}

Expand Down Expand Up @@ -93,13 +97,17 @@ + (void)addSpacesIfNeededinInput:(EnrichedTextInputView *)input {

// do the replacing
NSInteger offset = 0;
NSInteger postAddOffset = 0;
NSInteger postAddLocationOffset = 0;
NSInteger postAddLengthOffset = 0;
for(NSNumber *index in indexesToBeInserted) {
NSRange replaceRange = NSMakeRange([index integerValue] + offset, 1);
[TextInsertionUtils replaceText:@"\u200B\n" at:replaceRange additionalAttributes:nullptr input:input withSelection:NO];
offset += 1;
if([index integerValue] < preAddSelection.location) {
postAddOffset += 1;
postAddLocationOffset += 1;
}
if([index integerValue] >= preAddSelection.location && [index integerValue] < NSMaxRange(preAddSelection)) {
postAddLengthOffset += 1;
}
}

Expand All @@ -112,7 +120,7 @@ + (void)addSpacesIfNeededinInput:(EnrichedTextInputView *)input {

// fix the selection if needed
if([input->textView isFirstResponder]) {
input->textView.selectedRange = NSMakeRange(preAddSelection.location + postAddOffset, preAddSelection.length);
input->textView.selectedRange = NSMakeRange(preAddSelection.location + postAddLocationOffset, preAddSelection.length + postAddLengthOffset);
}
}

Expand Down
Loading