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

Commit 554a456

Browse files
authored
Reverts part of "fix auto-correction highlight on top left corner (Again)" (#45523)
This reverts part of #44779. Verified this to be the regression for flutter/flutter#133908. This pair of `textWill/DidChange` calls was added in Beta 1, in order to fix highlight region missing last character (more details [here](https://docs.google.com/document/d/1sM3HMv-SQin39yX1aPUU7vtGv7Hcef1Quc3QhRXBl6A/edit?resourcekey=0-SFYD8vmOIkXiXCZvB1Wlcw#heading=h.ddlvu2i2epyl)). However, that fix doesn't work anymore for Beta 7 - it turns out that in Beta 7, the system doesn't rely on the `selectionRects` to determine the highlight region anymore. Instead, the system relies on `firstRectForRange` API. So we fixed the system highlight in `firstRectForRange` in Beta 7. So even after reverting this change, the system highlight still works correctly in Beta 7. I was initially leaning towards keeping these calls even after Beta 7, because without it, the `selectionRects` are still out of sync with iOS text input system. (more details [here](https://docs.google.com/document/d/1sM3HMv-SQin39yX1aPUU7vtGv7Hcef1Quc3QhRXBl6A/edit?resourcekey=0-SFYD8vmOIkXiXCZvB1Wlcw)). However, I was able to verify that it is indeed `textWill/DidChange` that introduced the regression for IME inputs (It's unclear why they are related, so need further investigation). In summary, after this revert, system highlights are still in the right place, and with the right length. *List which issues are fixed by this PR. You must list at least one issue.* Fixes flutter/flutter#133908 *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 0e633ce commit 554a456

File tree

2 files changed

+3
-46
lines changed

2 files changed

+3
-46
lines changed

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,21 +2540,10 @@ - (void)setSelectionRects:(NSArray*)encodedRects {
25402540
: NSWritingDirectionRightToLeft]];
25412541
}
25422542

2543-
BOOL shouldNotifyTextChange = NO;
2544-
if (@available(iOS 17, *)) {
2545-
// Force UIKit to query the selectionRects again on iOS 17+
2546-
// This is to fix a bug on iOS 17+ where UIKit queries the outdated selectionRects after
2547-
// entering a character, resulting in auto-correction highlight region missing the last
2548-
// character.
2549-
shouldNotifyTextChange = YES;
2550-
}
2551-
if (shouldNotifyTextChange) {
2552-
[_activeView.inputDelegate textWillChange:_activeView];
2553-
}
2543+
// TODO(hellohuanlin): Investigate why notifying the text input system about text changes (via
2544+
// textWillChange and textDidChange APIs) causes a bug where we cannot enter text with IME
2545+
// keyboards. Issue: https://github.com/flutter/flutter/issues/133908
25542546
_activeView.selectionRects = rectsAsRect;
2555-
if (shouldNotifyTextChange) {
2556-
[_activeView.inputDelegate textDidChange:_activeView];
2557-
}
25582547
}
25592548

25602549
- (void)startLiveTextInput {

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

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -457,38 +457,6 @@ - (void)testInputHiderOverlapWithTextWhenScribbleIsDisabledAfterIOS17AndDoesNotO
457457
}
458458
}
459459

460-
- (void)testSetSelectionRectsNotifiesTextChangeAfterIOS17AndDoesNotNotifyBeforeIOS17 {
461-
FlutterTextInputPlugin* myInputPlugin =
462-
[[FlutterTextInputPlugin alloc] initWithDelegate:OCMClassMock([FlutterEngine class])];
463-
464-
FlutterMethodCall* setClientCall =
465-
[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
466-
arguments:@[ @(123), self.mutableTemplateCopy ]];
467-
[myInputPlugin handleMethodCall:setClientCall
468-
result:^(id _Nullable result){
469-
}];
470-
471-
id mockInputDelegate = OCMProtocolMock(@protocol(UITextInputDelegate));
472-
myInputPlugin.activeView.inputDelegate = mockInputDelegate;
473-
474-
NSArray<NSNumber*>* selectionRect = [NSArray arrayWithObjects:@0, @0, @100, @100, @0, @1, nil];
475-
NSArray* selectionRects = [NSArray arrayWithObjects:selectionRect, nil];
476-
FlutterMethodCall* methodCall =
477-
[FlutterMethodCall methodCallWithMethodName:@"Scribble.setSelectionRects"
478-
arguments:selectionRects];
479-
[myInputPlugin handleMethodCall:methodCall
480-
result:^(id _Nullable result){
481-
}];
482-
483-
if (@available(iOS 17.0, *)) {
484-
OCMVerify([mockInputDelegate textWillChange:myInputPlugin.activeView]);
485-
OCMVerify([mockInputDelegate textDidChange:myInputPlugin.activeView]);
486-
} else {
487-
OCMVerify(never(), [mockInputDelegate textWillChange:myInputPlugin.activeView]);
488-
OCMVerify(never(), [mockInputDelegate textDidChange:myInputPlugin.activeView]);
489-
}
490-
}
491-
492460
- (void)testTextRangeFromPositionMatchesUITextViewBehavior {
493461
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin];
494462
FlutterTextPosition* fromPosition = [FlutterTextPosition positionWithIndex:2];

0 commit comments

Comments
 (0)