Skip to content

Commit fa81a11

Browse files
authored
fix(ios): use controlled path for Cut to prevent formatting corruption (#278)
* fix(ios): prevent crash when deleting mixed selection or using IME input Always update _lastSelectedRange in textViewDidChangeSelection and textInputDidChangeSelection before the isApplyingFormatting guard, ensuring _preEditSelectedRange is never stale when handleTextChanged computes edit parameters. Also clamp modificationRange passed to the detector pipeline so out-of-bounds values cannot reach ENRMWordsUtils. Made-with: Cursor * fix(ios): use controlled path for Cut to prevent formatting corruption Route Cut through replaceSelectedTextWith:formattingRanges: instead of UIKit's replaceRange:withText: (iOS) / insertText:replacementRange: (macOS). The controlled path bypasses the delegate chain and calls adjustForEditAtLocation: with exact parameters, eliminating timing races that corrupt the formatting store on slower devices or low power mode. Made-with: Cursor
1 parent 78b4419 commit fa81a11

3 files changed

Lines changed: 3 additions & 5 deletions

File tree

ios/input/ENRMInputTextView.mm

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ - (void)copy:(id)sender
3434
- (void)cut:(id)sender
3535
{
3636
[self copy:sender];
37-
[self replaceRange:self.selectedTextRange withText:@""];
37+
[self.markdownTextInput replaceSelectedTextWith:@"" formattingRanges:@[]];
3838
}
3939

4040
- (void)paste:(id)sender
@@ -111,9 +111,7 @@ - (void)copy:(id)sender
111111
- (void)cut:(id)sender
112112
{
113113
[self copy:sender];
114-
if (self.selectedRange.length > 0) {
115-
[self insertText:@"" replacementRange:self.selectedRange];
116-
}
114+
[self.markdownTextInput replaceSelectedTextWith:@"" formattingRanges:@[]];
117115
}
118116

119117
- (void)paste:(id)sender

ios/input/EnrichedMarkdownTextInput.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
1111
- (CGSize)measureSize:(CGFloat)maxWidth;
1212
- (nullable NSString *)markdownForSelectedRange;
1313
- (void)pasteMarkdown:(NSString *)markdown;
14+
- (void)replaceSelectedTextWith:(NSString *)text formattingRanges:(NSArray *)ranges;
1415
- (void)scheduleRelayoutIfNeeded;
1516
@end
1617

ios/input/EnrichedMarkdownTextInput.mm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ - (void)setupTextView;
4141
- (void)applyFormatting;
4242
- (void)toggleInlineStyle:(ENRMInputStyleType)styleType;
4343
- (void)resetBaseTypingAttributes;
44-
- (void)replaceSelectedTextWith:(NSString *)text formattingRanges:(NSArray<ENRMFormattingRange *> *)ranges;
4544
@end
4645

4746
@implementation EnrichedMarkdownTextInput {

0 commit comments

Comments
 (0)