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
Clean up
  • Loading branch information
justinmc committed Sep 14, 2020
commit 44c766a5b8c2d1bc9411eba196b008d395ff8907
Original file line number Diff line number Diff line change
Expand Up @@ -996,11 +996,11 @@ - (void)updateEditingState {
@"text" : [NSString stringWithString:self.text],
};

// 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.
// Debounce calls to updateEditingClient on the leading edge. 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;
[self updateEditingClient];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,13 @@ - (void)testUITextInputCallsUpdateEditingStateOnce {
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] init];
inputView.textInputDelegate = engine;

XCTestExpectation* expectation2 = [self expectationWithDescription:@"called updateEditingClient twice"];
XCTestExpectation* expectation4 = [self expectationWithDescription:@"called updateEditingClient four times"];
XCTestExpectation* expectation6 = [self expectationWithDescription:@"called updateEditingClient six times"];
__block XCTestExpectation* expectation;
__block int updateCount = 0;
OCMStub([engine updateEditingClient:0 withState:[OCMArg isNotNil]])
.andDo(^(NSInvocation* invocation) {
updateCount++;
if (updateCount == 2) {
[expectation2 fulfill];
} else if (updateCount == 4) {
[expectation4 fulfill];
} else if (updateCount == 6) {
[expectation6 fulfill];
if (expectation != nil) {
[expectation fulfill];
}
});

Expand All @@ -195,10 +189,12 @@ - (void)testUITextInputCallsUpdateEditingStateOnce {
// because calls to updateEditingState are debounced on the leading edge.
XCTAssertEqual(updateCount, 1);

expectation = [self expectationWithDescription:@"called updateEditingClient"];
[inputView deleteBackward];
// Due to the debouncing, this call will happen after a short delay.
XCTAssertEqual(updateCount, 1);
[self waitForExpectations:@[expectation2] timeout:1];
[self waitForExpectations:@[expectation] timeout:1];
expectation = nil;
XCTAssertEqual(updateCount, 2);

// Subsequent calls follow this pattern of leading edge debouncing. Now that
Expand All @@ -208,32 +204,36 @@ - (void)testUITextInputCallsUpdateEditingStateOnce {
inputView.selectedTextRange = [FlutterTextRange rangeWithNSRange:NSMakeRange(0, 1)];
XCTAssertEqual(updateCount, 3);

expectation = [self expectationWithDescription:@"called updateEditingClient"];
[inputView replaceRange:[FlutterTextRange rangeWithNSRange:NSMakeRange(0, 1)]
withText:@"replace text"];
XCTAssertEqual(updateCount, 3);
[self waitForExpectations:@[expectation4] timeout:1];
[self waitForExpectations:@[expectation] timeout:1];
expectation = nil;
XCTAssertEqual(updateCount, 4);

[inputView setMarkedText:@"marked text" selectedRange:NSMakeRange(0, 1)];
XCTAssertEqual(updateCount, 5);

expectation = [self expectationWithDescription:@"called updateEditingClient"];
[inputView unmarkText];
XCTAssertEqual(updateCount, 5);
[self waitForExpectations:@[expectation6] timeout:1];
[self waitForExpectations:@[expectation] timeout:1];
expectation = nil;
XCTAssertEqual(updateCount, 6);
}

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

XCTestExpectation* expectation2 = [self expectationWithDescription:@"called updateEditingClient twice"];
__block XCTestExpectation* expectation;
__block int updateCount = 0;
OCMStub([engine updateEditingClient:0 withState:[OCMArg isNotNil]])
.andDo(^(NSInvocation* invocation) {
updateCount++;
if (updateCount == 2) {
[expectation2 fulfill];
if (expectation != nil) {
[expectation fulfill];
}
});

Expand All @@ -243,11 +243,12 @@ - (void)testUITextInputCallsToUpdateEditingStateAreDebounced {
XCTAssertEqual(updateCount, 1);

// These calls will be batched and come through after a short delay.
expectation = [self expectationWithDescription:@"called updateEditingClient twice"];
[inputView deleteBackward];
[inputView deleteBackward];
[inputView deleteBackward];
XCTAssertEqual(updateCount, 1);
[self waitForExpectations:@[expectation2] timeout:1];
[self waitForExpectations:@[expectation] timeout:1];
XCTAssertEqual(updateCount, 2);
XCTAssertTrue([inputView.text isEqualToString:@"text to ins"]);
}
Expand Down Expand Up @@ -365,17 +366,14 @@ - (void)testUpdateEditingClientSelectionClamping {
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] init];
inputView.textInputDelegate = engine;

// Debounced calls need to be waited for using these expectations.
XCTestExpectation* expectation2 = [self expectationWithDescription:@"called updateEditingClient twice"];
XCTestExpectation* expectation4 = [self expectationWithDescription:@"called updateEditingClient four times"];
// Debounced calls need to be waited for using this expectation.
__block XCTestExpectation* expectation;
__block int updateCount = 0;
OCMStub([engine updateEditingClient:0 withState:[OCMArg isNotNil]])
.andDo(^(NSInvocation* invocation) {
updateCount++;
if (updateCount == 2) {
[expectation2 fulfill];
} else if (updateCount == 4) {
[expectation4 fulfill];
if (expectation != nil) {
[expectation fulfill];
}
});

Expand All @@ -393,14 +391,16 @@ - (void)testUpdateEditingClientSelectionClamping {
}]]);

// Needs clamping.
expectation = [self expectationWithDescription:@"called updateEditingClient"];
[inputView setTextInputState:@{
@"text" : @"SELECTION",
@"selectionBase" : @0,
@"selectionExtent" : @9999
}];
[inputView updateEditingState];

[self waitForExpectations:@[expectation2] timeout:1];
[self waitForExpectations:@[expectation] timeout:1];
expectation = nil;
OCMVerify([engine updateEditingClient:0
withState:[OCMArg checkWithBlock:^BOOL(NSDictionary* state) {
return ([state[@"selectionBase"] intValue]) == 0 &&
Expand All @@ -418,13 +418,15 @@ - (void)testUpdateEditingClientSelectionClamping {
}]]);

// Both ends need clamping.
expectation = [self expectationWithDescription:@"called updateEditingClient"];
[inputView setTextInputState:@{
@"text" : @"SELECTION",
@"selectionBase" : @9999,
@"selectionExtent" : @9999
}];
[inputView updateEditingState];
[self waitForExpectations:@[expectation4] timeout:1];
[self waitForExpectations:@[expectation] timeout:1];
expectation = nil;
OCMVerify([engine updateEditingClient:0
withState:[OCMArg checkWithBlock:^BOOL(NSDictionary* state) {
return ([state[@"selectionBase"] intValue]) == 9 &&
Expand Down