Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
WIP Trying to fix tests
  • Loading branch information
justinmc committed Jul 30, 2020
commit a97991191aadc21cd2ade048f12112769f9a005b
Original file line number Diff line number Diff line change
Expand Up @@ -784,27 +784,47 @@ - (void)updateEditingState {
@"composingExtent" : @(composingExtent),
@"text" : [NSString stringWithString:self.text],
};
_latestState = state;

// Debounce calls to updateEditingClient. This makes iOS text editing behave
// more similarly to Android's, which has built-in event batching, and avoids
// race conditions. The delay value was chosen to be imperceptible by the user
// but still long enough to allow the framework to respond with formatting
// updates, thereby avoiding common race conditions.
if (_latestState == nil) {
_latestState = state;
NSLog(@"justin leading edge updateEditingClient for %@", _latestState[@"text"]);
[self updateEditingClient];
NSLog(@"justin 1");
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10000000), dispatch_get_main_queue(), ^(void){
NSLog(@"justin 2");
if (_latestState == state) {
NSLog(@"justin updateEditingClient clear leading edge for %@", _latestState[@"text"]);
_latestState = nil;
}
});
NSLog(@"justin 3");
return;
}
_latestState = state;
NSLog(@"justin updateEditingClient start trailing edge timer for _latestState for %@", _latestState[@"text"]);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10000000), dispatch_get_main_queue(), ^(void){
if (state != _latestState) {
return;
}
NSLog(@"justin trailing edge updateEditingClient for %@", _latestState[@"text"]);
[self updateEditingClient];
_latestState = nil;

if (_textInputClient == 0 && _autofillId != nil) {
[_textInputDelegate updateEditingClient:_textInputClient withState:state withTag:_autofillId];
} else {
[_textInputDelegate updateEditingClient:_textInputClient withState:state];
}
});
}

- (void)updateEditingClient {
if (_textInputClient == 0 && _autofillId != nil) {
[_textInputDelegate updateEditingClient:_textInputClient withState:_latestState withTag:_autofillId];
} else {
[_textInputDelegate updateEditingClient:_textInputClient withState:_latestState];
}
}

- (BOOL)hasText {
return self.text.length > 0;
}
Expand Down Expand Up @@ -1036,6 +1056,7 @@ + (void)setupInputView:(FlutterTextInputView*)inputView

- (void)setTextInputEditingState:(NSDictionary*)state {
if ([_activeView setTextInputState:state]) {
NSLog(@"justin setTextInputEditingState for %@", state[@"text"]);
[_activeView updateEditingState];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,36 +245,62 @@ - (void)testTextRangeFromPositionMatchesUITextViewBehavior {
}

- (void)testUITextInputCallsUpdateEditingStateOnce {
NSLog(@"justin start testUITextInputCallsUpdateEditingStateOnce");
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] init];
inputView.textInputDelegate = engine;

XCTestExpectation* expectation = [self expectationWithDescription:@"called updateEditingClient"];
XCTestExpectation* expectation3 = [self expectationWithDescription:@"called four times"];
NSString* text;
__block bool calledSinceChange = false;
__block int updateCount = 0;
OCMStub([engine updateEditingClient:0 withState:[OCMArg isNotNil]])
.andDo(^(NSInvocation* invocation) {
XCTAssertEqual(calledSinceChange, false);
calledSinceChange = true;
updateCount++;
if (updateCount == 1) {
[expectation fulfill];
} else if (updateCount == 3) {
[expectation3 fulfill];
}
});

text = @"text to insert";
NSLog(@"justin testUITextInputCallsUpdateEditingStateOnce insertText 1");
[inputView insertText:@"text to insert"];
NSLog(@"justin testUITextInputCallsUpdateEditingStateOnce insertedText 1");
// Update the framework exactly once.
XCTAssertEqual(updateCount, 1);
calledSinceChange = false;

expectation = [self expectationWithDescription:@"called updateEditingClient"];
text = @"text to inser";
[inputView deleteBackward];
XCTAssertEqual(updateCount, 1);
[self waitForExpectations:@[expectation] timeout:1];
XCTAssertEqual(updateCount, 2);

inputView.selectedTextRange = [FlutterTextRange rangeWithNSRange:NSMakeRange(0, 1)];
XCTAssertEqual(updateCount, 3);

[inputView replaceRange:[FlutterTextRange rangeWithNSRange:NSMakeRange(0, 1)]
withText:@"replace text"];
XCTAssertEqual(updateCount, 3);
[self waitForExpectations:@[expectation3] timeout:1];
XCTAssertEqual(updateCount, 4);

/*
[inputView setMarkedText:@"marked text" selectedRange:NSMakeRange(0, 1)];
[self waitForExpectations:@[expectation4] timeout:1];
XCTAssertEqual(updateCount, 5);

[inputView unmarkText];
XCTAssertEqual(updateCount, 6);
*/
}

/*
- (void)testBackToBackUITextInputCallsUpdateEditingStateOnce {
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] init];
inputView.textInputDelegate = engine;
Expand Down Expand Up @@ -306,4 +332,5 @@ - (void)testBackToBackUITextInputCallsUpdateEditingStateOnce {
[inputView unmarkText];
XCTAssertEqual(updateCount, 6);
}
*/
@end