diff --git a/ios/styles/BlockQuoteStyle.mm b/ios/styles/BlockQuoteStyle.mm index 6f97def79..71ade37ed 100644 --- a/ios/styles/BlockQuoteStyle.mm +++ b/ios/styles/BlockQuoteStyle.mm @@ -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; } } diff --git a/ios/styles/OrderedListStyle.mm b/ios/styles/OrderedListStyle.mm index 2963b0a06..e4f9a5f5f 100644 --- a/ios/styles/OrderedListStyle.mm +++ b/ios/styles/OrderedListStyle.mm @@ -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; } } diff --git a/ios/styles/UnorderedListStyle.mm b/ios/styles/UnorderedListStyle.mm index 6cec6bdd9..95270ca51 100644 --- a/ios/styles/UnorderedListStyle.mm +++ b/ios/styles/UnorderedListStyle.mm @@ -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; } } diff --git a/ios/utils/ZeroWidthSpaceUtils.mm b/ios/utils/ZeroWidthSpaceUtils.mm index 587113245..63f76a4a1 100644 --- a/ios/utils/ZeroWidthSpaceUtils.mm +++ b/ios/utils/ZeroWidthSpaceUtils.mm @@ -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); } } @@ -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; } } @@ -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); } }