Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7f953c3

Browse files
committed
Address some feedback
1 parent abea01d commit 7f953c3

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,7 @@ - (CGRect)firstRectForRange:(UITextRange*)range {
16291629

16301630
- (CGRect)caretRectForPosition:(UITextPosition*)position {
16311631
NSInteger index = ((FlutterTextPosition*)position).index;
1632+
// Get the bounds of the characters before and after the requested caret position.
16321633
NSArray<UITextSelectionRect*>* rects =
16331634
[self selectionRectsForRange:[FlutterTextRange
16341635
rangeWithNSRange:fml::RangeForCharactersInRange(
@@ -1638,10 +1639,17 @@ - (CGRect)caretRectForPosition:(UITextPosition*)position {
16381639
return CGRectZero;
16391640
}
16401641
if (index == 0) {
1641-
return CGRectMake(rects[0].rect.origin.x, rects[0].rect.origin.y, 0, rects[0].rect.size.height);
1642+
// There is no character before the caret, so this will be the bounds of the character after the
1643+
// caret position.
1644+
CGRect characterAfterCaret = rects[0].rect;
1645+
// Return a zero-width rectangle along the left edge of the character after the caret position.
1646+
return CGRectMake(characterAfterCaret.origin.x, characterAfterCaret.origin.y, 0,
1647+
characterAfterCaret.size.height);
16421648
}
1643-
return CGRectMake(rects[0].rect.origin.x + rects[0].rect.size.width, rects[0].rect.origin.y, 0,
1644-
rects[0].rect.size.height);
1649+
CGRect characterBeforeCaret = rects[0].rect;
1650+
// Return a zero-width rectangle along the right edge of the character before the caret position.
1651+
return CGRectMake(characterBeforeCaret.origin.x + characterBeforeCaret.size.width,
1652+
characterBeforeCaret.origin.y, 0, characterBeforeCaret.size.height);
16451653
}
16461654

16471655
- (UITextPosition*)closestPositionToPoint:(CGPoint)point {
@@ -1761,7 +1769,7 @@ - (void)beginFloatingCursorAtPoint:(CGPoint)point {
17611769
[self.textInputDelegate flutterTextInputView:self
17621770
updateFloatingCursor:FlutterFloatingCursorDragStateStart
17631771
withClient:_textInputClient
1764-
withPosition:@{@"X" : @(0), @"Y" : @(0)}];
1772+
withPosition:@{@"X" : @0, @"Y" : @0}];
17651773
}
17661774

17671775
- (void)updateFloatingCursorAtPoint:(CGPoint)point {
@@ -1780,7 +1788,7 @@ - (void)endFloatingCursor {
17801788
[self.textInputDelegate flutterTextInputView:self
17811789
updateFloatingCursor:FlutterFloatingCursorDragStateEnd
17821790
withClient:_textInputClient
1783-
withPosition:@{@"X" : @(0), @"Y" : @(0)}];
1791+
withPosition:@{@"X" : @0, @"Y" : @0}];
17841792
}
17851793

17861794
#pragma mark - UIKeyInput Overrides

0 commit comments

Comments
 (0)