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

Commit 630710e

Browse files
committed
WIP Trying to fix tests
1 parent 5de9e67 commit 630710e

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -784,27 +784,44 @@ - (void)updateEditingState {
784784
@"composingExtent" : @(composingExtent),
785785
@"text" : [NSString stringWithString:self.text],
786786
};
787-
_latestState = state;
788787

789788
// Debounce calls to updateEditingClient. This makes iOS text editing behave
790789
// more similarly to Android's, which has built-in event batching, and avoids
791790
// race conditions. The delay value was chosen to be imperceptible by the user
792791
// but still long enough to allow the framework to respond with formatting
793792
// updates, thereby avoiding common race conditions.
793+
if (_latestState == nil) {
794+
_latestState = state;
795+
NSLog(@"justin leading edge updateEditingClient for %@", _latestState[@"text"]);
796+
[self updateEditingClient];
797+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10000000), dispatch_get_main_queue(), ^(void){
798+
if (_latestState == state) {
799+
NSLog(@"justin updateEditingClient clear leading edge for %@", _latestState[@"text"]);
800+
_latestState = nil;
801+
}
802+
});
803+
return;
804+
}
805+
_latestState = state;
806+
NSLog(@"justin updateEditingClient start trailing edge timer for _latestState for %@", _latestState[@"text"]);
794807
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10000000), dispatch_get_main_queue(), ^(void){
795808
if (state != _latestState) {
796809
return;
797810
}
811+
NSLog(@"justin trailing edge updateEditingClient for %@", _latestState[@"text"]);
812+
[self updateEditingClient];
798813
_latestState = nil;
799-
800-
if (_textInputClient == 0 && _autofillId != nil) {
801-
[_textInputDelegate updateEditingClient:_textInputClient withState:state withTag:_autofillId];
802-
} else {
803-
[_textInputDelegate updateEditingClient:_textInputClient withState:state];
804-
}
805814
});
806815
}
807816

817+
- (void)updateEditingClient {
818+
if (_textInputClient == 0 && _autofillId != nil) {
819+
[_textInputDelegate updateEditingClient:_textInputClient withState:_latestState withTag:_autofillId];
820+
} else {
821+
[_textInputDelegate updateEditingClient:_textInputClient withState:_latestState];
822+
}
823+
}
824+
808825
- (BOOL)hasText {
809826
return self.text.length > 0;
810827
}
@@ -1036,6 +1053,7 @@ + (void)setupInputView:(FlutterTextInputView*)inputView
10361053

10371054
- (void)setTextInputEditingState:(NSDictionary*)state {
10381055
if ([_activeView setTextInputState:state]) {
1056+
NSLog(@"justin setTextInputEditingState for %@", state[@"text"]);
10391057
[_activeView updateEditingState];
10401058
}
10411059
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,41 @@ - (void)testUITextInputCallsUpdateEditingStateOnce {
248248
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] init];
249249
inputView.textInputDelegate = engine;
250250

251+
XCTestExpectation* expectation = [self expectationWithDescription:@"called updateEditingClient"];
252+
//XCTestExpectation* expectation2 = [self expectationWithDescription:@"called twice"];
253+
//XCTestExpectation* expectation4 = [self expectationWithDescription:@"called four times"];
254+
NSString* text;
255+
__block bool calledSinceChange = false;
251256
__block int updateCount = 0;
252257
OCMStub([engine updateEditingClient:0 withState:[OCMArg isNotNil]])
253258
.andDo(^(NSInvocation* invocation) {
259+
XCTAssertEqual(calledSinceChange, false);
260+
calledSinceChange = true;
261+
NSDictionary* state;
262+
[invocation getArgument:&state atIndex:1];
263+
// TODO(justinmc): It's throwing an error when you try to access "text".
264+
XCTAssertEqual(state[@"text"], text);
254265
updateCount++;
266+
[expectation fulfill];
267+
/*
268+
if (updateCount == 2) {
269+
[expectation2 fulfill];
270+
} else if (updateCount == 4) {
271+
[expectation4 fulfill];
272+
}
273+
*/
255274
});
256275

276+
text = @"text to insert";
257277
[inputView insertText:@"text to insert"];
258278
// Update the framework exactly once.
259279
XCTAssertEqual(updateCount, 1);
280+
calledSinceChange = false;
260281

282+
expectation = [self expectationWithDescription:@"called updateEditingClient"];
283+
text = @"text to inser";
261284
[inputView deleteBackward];
285+
[self waitForExpectations:@[expectation] timeout:1];
262286
XCTAssertEqual(updateCount, 2);
263287

264288
inputView.selectedTextRange = [FlutterTextRange rangeWithNSRange:NSMakeRange(0, 1)];
@@ -268,11 +292,14 @@ - (void)testUITextInputCallsUpdateEditingStateOnce {
268292
withText:@"replace text"];
269293
XCTAssertEqual(updateCount, 4);
270294

295+
/*
271296
[inputView setMarkedText:@"marked text" selectedRange:NSMakeRange(0, 1)];
297+
[self waitForExpectations:@[expectation4] timeout:1];
272298
XCTAssertEqual(updateCount, 5);
273299
274300
[inputView unmarkText];
275301
XCTAssertEqual(updateCount, 6);
302+
*/
276303
}
277304

278305
- (void)testBackToBackUITextInputCallsUpdateEditingStateOnce {

0 commit comments

Comments
 (0)