Skip to content

Commit eccacb6

Browse files
fix(iOS): idx out of bounds crash inside caretRectForPosition (#611)
# Summary Fixes: `idx` out of bounds crash inside `caretRectForPosition` ## Test Plan 1. Write in input: test 2. press enter 3. toggle center alignment 4. Write in input: test 5. select whole text and delete it 6. press with cursor outside of simulator 7. press in input The crash should not occur ## Screenshots / Videos n/a ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | Android | ❌ | ## Checklist - [ ] E2E tests are passing - [ ] Required E2E tests have been added (if applicable)
1 parent 68f1e37 commit eccacb6

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

ios/enrichedInputTextView/EnrichedInputTextView.mm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ - (CGRect)caretRectForPosition:(UITextPosition *)position {
2828
NSUInteger idx = [self offsetFromPosition:self.beginningOfDocument
2929
toPosition:position];
3030
NSString *text = self.textStorage.string;
31-
NSRange paraRange = [text paragraphRangeForRange:NSMakeRange(idx, 0)];
31+
NSRange paraRange = NSMakeRange(0, 0);
32+
if (idx <= text.length) {
33+
paraRange = [text paragraphRangeForRange:NSMakeRange(idx, 0)];
34+
}
3235

3336
// Non-empty paragraph gets its caret drawn the usual way.
3437
if (paraRange.length != 0) {

0 commit comments

Comments
 (0)