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

iOS Text Editing Infinite Loop #20160

Merged
merged 22 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2a27aa1
Turn -1s into 0s instead of letting them overflow and cause weird res…
justinmc Jul 15, 2020
9ab67dd
For invalid selection, set it to nil instead of zero
justinmc Jul 16, 2020
65a27d8
Avoid bugs where a range is expected by setting range to 0,0 instead …
justinmc Jul 17, 2020
c9baf78
Avoid race condition by debouncing editing calls to framework
justinmc Jul 17, 2020
145fa27
Test that calls are batched
justinmc Jul 21, 2020
5de9e67
Clean up logging and comments
justinmc Jul 21, 2020
a979911
WIP Trying to fix tests
justinmc Jul 22, 2020
f6b9ea8
Merge branch 'master' into ios-range-overflow-infinite-loop
justinmc Aug 7, 2020
58b0e55
Merge branch 'master' into ios-range-overflow-infinite-loop
justinmc Aug 7, 2020
2e1b0b5
Merge branch 'master' into ios-range-overflow-infinite-loop
justinmc Sep 10, 2020
87d2119
Merge branch 'master' into ios-range-overflow-infinite-loop
justinmc Sep 11, 2020
ea19ac2
fix testUITextInputCallsUpdateEditingStateOnce
justinmc Sep 11, 2020
da16787
Existing tests pass by waiting for debounced calls.
justinmc Sep 11, 2020
3928860
Test batching
justinmc Sep 14, 2020
44c766a
Clean up
justinmc Sep 14, 2020
9949623
release _latestState
justinmc Sep 18, 2020
43ae4eb
Merge branch 'master' into ios-range-overflow-infinite-loop
justinmc Sep 23, 2020
a87230b
Dont send an ack back to the framework for text changes. The reason w…
justinmc Sep 23, 2020
255efbb
Test that the client isn't updated with its own text changes
justinmc Sep 23, 2020
bca94b6
Update return type in test
justinmc Oct 1, 2020
c36382c
Also test selection and composing changes
justinmc Oct 1, 2020
5c01b17
Merge branch 'master' into ios-range-overflow-infinite-loop
justinmc Oct 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,7 @@ - (void)setTextInputClient:(int)client {
_textInputClient = client;
}

// Return true if the new input state needs to be synced back to the framework.
// TODO(LongCatIsLooong): setTextInputState should never call updateEditingState. Sending the
// editing value back may overwrite the framework's updated editing value.
- (BOOL)setTextInputState:(NSDictionary*)state {
- (void)setTextInputState:(NSDictionary*)state {
NSString* newText = state[@"text"];
BOOL textChanged = ![self.text isEqualToString:newText];
if (textChanged) {
Expand Down Expand Up @@ -575,9 +572,6 @@ - (BOOL)setTextInputState:(NSDictionary*)state {
if (textChanged) {
[self.inputDelegate textDidChange:self];
}

// For consistency with Android behavior, send an update to the framework if the text changed.
return textChanged;
}

// Extracts the selection information from the editing state dictionary.
Expand Down Expand Up @@ -1423,9 +1417,7 @@ - (void)addToInputParentViewIfNeeded:(FlutterTextInputView*)inputView {
}

- (void)setTextInputEditingState:(NSDictionary*)state {
if ([_activeView setTextInputState:state]) {
[_activeView updateEditingState];
}
[_activeView setTextInputState:state];
}

- (void)clearTextInputClient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ @interface FlutterTextInputView ()
@property(nonatomic, copy) NSString* autofillId;

- (void)setEditableTransform:(NSArray*)matrix;
- (BOOL)setTextInputState:(NSDictionary*)state;
- (void)setTextInputState:(NSDictionary*)state;
- (void)setMarkedRect:(CGRect)markedRect;
- (void)updateEditingState;
- (BOOL)isVisibleToAutofill;
Expand Down Expand Up @@ -211,71 +211,45 @@ - (void)testUITextInputCallsUpdateEditingStateOnce {
XCTAssertEqual(updateCount, 6);
}

- (void)testTextChangesTriggerUpdateEditingClient {
- (void)testTextChangesDoNotTriggerUpdateEditingClient {
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] init];
inputView.textInputDelegate = engine;

[inputView.text setString:@"BEFORE"];
inputView.markedTextRange = nil;
inputView.selectedTextRange = nil;

// Text changes trigger update.
XCTAssertTrue([inputView setTextInputState:@{@"text" : @"AFTER"}]);

// Don't send anything if there's nothing new.
XCTAssertFalse([inputView setTextInputState:@{@"text" : @"AFTER"}]);
}
__block int updateCount = 0;
OCMStub([engine updateEditingClient:0 withState:[OCMArg isNotNil]])
.andDo(^(NSInvocation* invocation) {
updateCount++;
});

- (void)testSelectionChangeDoesNotTriggerUpdateEditingClient {
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] init];
inputView.textInputDelegate = engine;
[inputView.text setString:@"BEFORE"];
XCTAssertEqual(updateCount, 0);

[inputView.text setString:@"SELECTION"];
inputView.markedTextRange = nil;
inputView.selectedTextRange = nil;
XCTAssertEqual(updateCount, 1);

BOOL shouldUpdate = [inputView
setTextInputState:@{@"text" : @"SELECTION", @"selectionBase" : @0, @"selectionExtent" : @3}];
XCTAssertFalse(shouldUpdate);
// Text changes don't trigger an update.
XCTAssertEqual(updateCount, 1);
[inputView setTextInputState:@{@"text" : @"AFTER"}];
XCTAssertEqual(updateCount, 1);
[inputView setTextInputState:@{@"text" : @"AFTER"}];
XCTAssertEqual(updateCount, 1);

shouldUpdate = [inputView
// Selection changes don't trigger an update.
[inputView
setTextInputState:@{@"text" : @"SELECTION", @"selectionBase" : @0, @"selectionExtent" : @3}];
XCTAssertEqual(updateCount, 1);
[inputView
setTextInputState:@{@"text" : @"SELECTION", @"selectionBase" : @1, @"selectionExtent" : @3}];
XCTAssertFalse(shouldUpdate);

shouldUpdate = [inputView
setTextInputState:@{@"text" : @"SELECTION", @"selectionBase" : @1, @"selectionExtent" : @2}];
XCTAssertFalse(shouldUpdate);

// Don't send anything if there's nothing new.
shouldUpdate = [inputView
setTextInputState:@{@"text" : @"SELECTION", @"selectionBase" : @1, @"selectionExtent" : @2}];
XCTAssertFalse(shouldUpdate);
}

- (void)testComposingChangeDoesNotTriggerUpdateEditingClient {
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] init];
inputView.textInputDelegate = engine;

// Reset to test marked text.
[inputView.text setString:@"COMPOSING"];
inputView.markedTextRange = nil;
inputView.selectedTextRange = nil;

BOOL shouldUpdate = [inputView
setTextInputState:@{@"text" : @"COMPOSING", @"composingBase" : @0, @"composingExtent" : @3}];
XCTAssertFalse(shouldUpdate);

shouldUpdate = [inputView
setTextInputState:@{@"text" : @"COMPOSING", @"composingBase" : @1, @"composingExtent" : @3}];
XCTAssertFalse(shouldUpdate);

shouldUpdate = [inputView
setTextInputState:@{@"text" : @"COMPOSING", @"composingBase" : @1, @"composingExtent" : @2}];
XCTAssertFalse(shouldUpdate);
XCTAssertEqual(updateCount, 1);

shouldUpdate = [inputView
// Composing region changes don't trigger an update.
[inputView
setTextInputState:@{@"text" : @"COMPOSING", @"composingBase" : @1, @"composingExtent" : @2}];
XCTAssertFalse(shouldUpdate);
XCTAssertEqual(updateCount, 1);
[inputView
setTextInputState:@{@"text" : @"COMPOSING", @"composingBase" : @1, @"composingExtent" : @3}];
XCTAssertEqual(updateCount, 1);
}

- (void)testUITextInputAvoidUnnecessaryUndateEditingClientCalls {
Expand Down