Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverts part of "fix auto-correction highlight on top left corner (Again)" #45523

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2540,21 +2540,10 @@ - (void)setSelectionRects:(NSArray*)encodedRects {
: NSWritingDirectionRightToLeft]];
}

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

- (void)startLiveTextInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,38 +457,6 @@ - (void)testInputHiderOverlapWithTextWhenScribbleIsDisabledAfterIOS17AndDoesNotO
}
}

- (void)testSetSelectionRectsNotifiesTextChangeAfterIOS17AndDoesNotNotifyBeforeIOS17 {
FlutterTextInputPlugin* myInputPlugin =
[[FlutterTextInputPlugin alloc] initWithDelegate:OCMClassMock([FlutterEngine class])];

FlutterMethodCall* setClientCall =
[FlutterMethodCall methodCallWithMethodName:@"TextInput.setClient"
arguments:@[ @(123), self.mutableTemplateCopy ]];
[myInputPlugin handleMethodCall:setClientCall
result:^(id _Nullable result){
}];

id mockInputDelegate = OCMProtocolMock(@protocol(UITextInputDelegate));
myInputPlugin.activeView.inputDelegate = mockInputDelegate;

NSArray<NSNumber*>* selectionRect = [NSArray arrayWithObjects:@0, @0, @100, @100, @0, @1, nil];
NSArray* selectionRects = [NSArray arrayWithObjects:selectionRect, nil];
FlutterMethodCall* methodCall =
[FlutterMethodCall methodCallWithMethodName:@"Scribble.setSelectionRects"
arguments:selectionRects];
[myInputPlugin handleMethodCall:methodCall
result:^(id _Nullable result){
}];

if (@available(iOS 17.0, *)) {
OCMVerify([mockInputDelegate textWillChange:myInputPlugin.activeView]);
OCMVerify([mockInputDelegate textDidChange:myInputPlugin.activeView]);
} else {
OCMVerify(never(), [mockInputDelegate textWillChange:myInputPlugin.activeView]);
OCMVerify(never(), [mockInputDelegate textDidChange:myInputPlugin.activeView]);
}
}

- (void)testTextRangeFromPositionMatchesUITextViewBehavior {
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin];
FlutterTextPosition* fromPosition = [FlutterTextPosition positionWithIndex:2];
Expand Down