[macOS] Do not bounce editing state back to framework on setEditState (flutter/engine#42091)

Some context for this change https://github.com/flutter/flutter/issues/118642#issuecomment-1550864240 and https://github.com/flutter/flutter/issues/118759#issuecomment-1551906489 . Tldr, the use-case that this bouncing was originally introduced for in #13702 is no longer an issue.

This ack response is also not present on other desktop platforms or iOS.

Fixes [#118759](https://github.com/flutter/flutter/issues/118759) and [#118642](https://github.com/flutter/flutter/issues/118642)
This commit is contained in:
Renzo Olivares
2023-05-26 14:07:02 -07:00
committed by GitHub
parent ad6f346f5f
commit ea95b85e63
2 changed files with 45 additions and 120 deletions

View File

@@ -448,19 +448,6 @@ static char markerKey;
} else if ([method isEqualToString:kSetEditingStateMethod]) { } else if ([method isEqualToString:kSetEditingStateMethod]) {
NSDictionary* state = call.arguments; NSDictionary* state = call.arguments;
[self setEditingState:state]; [self setEditingState:state];
// Close the loop, since the framework state could have been updated by the
// engine since it sent this update, and needs to now be made to match the
// engine's version of the state.
if (!_enableDeltaModel) {
[self updateEditState];
} else {
// Send an "empty" delta. The client can compare the old_text with their
// current text and update with that if the race condition described above
// occurs.
[self updateEditStateWithDelta:flutter::TextEditingDelta(_activeModel->GetText().c_str(),
flutter::TextRange(0, 0), "")];
}
} else if ([method isEqualToString:kSetEditableSizeAndTransform]) { } else if ([method isEqualToString:kSetEditableSizeAndTransform]) {
NSDictionary* state = call.arguments; NSDictionary* state = call.arguments;
[self setEditableTransform:state[kTransformKey]]; [self setEditableTransform:state[kTransformKey]];

View File

@@ -87,34 +87,19 @@
@"composingExtent" : @(-1), @"composingExtent" : @(-1),
}]; }];
NSDictionary* expectedState = @{
@"selectionBase" : @(0),
@"selectionExtent" : @(0),
@"selectionAffinity" : @"TextAffinity.upstream",
@"selectionIsDirectional" : @(NO),
@"composingBase" : @(-1),
@"composingExtent" : @(-1),
@"text" : @"Text",
};
NSData* updateCall = [[FlutterJSONMethodCodec sharedInstance]
encodeMethodCall:[FlutterMethodCall
methodCallWithMethodName:@"TextInputClient.updateEditingState"
arguments:@[ @(1), expectedState ]]];
OCMExpect( // NOLINT(google-objc-avoid-throwing-exception)
[binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]);
[plugin handleMethodCall:call [plugin handleMethodCall:call
result:^(id){ result:^(id){
}]; }];
@try { // Verify editing state was set.
OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) NSDictionary* editingState = [plugin editingState];
[binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]); EXPECT_STREQ([editingState[@"text"] UTF8String], "Text");
} @catch (...) { EXPECT_STREQ([editingState[@"selectionAffinity"] UTF8String], "TextAffinity.upstream");
return false; EXPECT_FALSE([editingState[@"selectionIsDirectional"] boolValue]);
} EXPECT_EQ([editingState[@"selectionBase"] intValue], 0);
EXPECT_EQ([editingState[@"selectionExtent"] intValue], 0);
EXPECT_EQ([editingState[@"composingBase"] intValue], -1);
EXPECT_EQ([editingState[@"composingExtent"] intValue], -1);
return true; return true;
} }
@@ -298,30 +283,15 @@
result:^(id){ result:^(id){
}]; }];
NSDictionary* expectedState = @{ // Verify editing state was set.
@"selectionBase" : @(2), NSDictionary* editingState = [plugin editingState];
@"selectionExtent" : @(2), EXPECT_STREQ([editingState[@"text"] UTF8String], "Te");
@"selectionAffinity" : @"TextAffinity.upstream", EXPECT_STREQ([editingState[@"selectionAffinity"] UTF8String], "TextAffinity.upstream");
@"selectionIsDirectional" : @(NO), EXPECT_FALSE([editingState[@"selectionIsDirectional"] boolValue]);
@"composingBase" : @(-1), EXPECT_EQ([editingState[@"selectionBase"] intValue], 2);
@"composingExtent" : @(-1), EXPECT_EQ([editingState[@"selectionExtent"] intValue], 2);
@"text" : @"Te", EXPECT_EQ([editingState[@"composingBase"] intValue], -1);
}; EXPECT_EQ([editingState[@"composingExtent"] intValue], -1);
NSData* updateCall = [[FlutterJSONMethodCodec sharedInstance]
encodeMethodCall:[FlutterMethodCall
methodCallWithMethodName:@"TextInputClient.updateEditingState"
arguments:@[ @(1), expectedState ]]];
OCMExpect( // NOLINT(google-objc-avoid-throwing-exception)
[binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]);
@try {
OCMVerify( // NOLINT(google-objc-avoid-throwing-exception)
[binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]);
} @catch (...) {
return false;
}
return true; return true;
} }
@@ -902,20 +872,15 @@
result:^(id){ result:^(id){
}]; }];
// The setEditingState call is ACKed back to the framework. // Verify editing state was set.
@try { NSDictionary* editingState = [plugin editingState];
OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) EXPECT_STREQ([editingState[@"text"] UTF8String], "Text");
[binaryMessengerMock EXPECT_STREQ([editingState[@"selectionAffinity"] UTF8String], "TextAffinity.upstream");
sendOnChannel:@"flutter/textinput" EXPECT_FALSE([editingState[@"selectionIsDirectional"] boolValue]);
message:[OCMArg checkWithBlock:^BOOL(NSData* callData) { EXPECT_EQ([editingState[@"selectionBase"] intValue], 0);
FlutterMethodCall* call = EXPECT_EQ([editingState[@"selectionExtent"] intValue], 0);
[[FlutterJSONMethodCodec sharedInstance] decodeMethodCall:callData]; EXPECT_EQ([editingState[@"composingBase"] intValue], -1);
return [[call method] EXPECT_EQ([editingState[@"composingExtent"] intValue], -1);
isEqualToString:@"TextInputClient.updateEditingStateWithDeltas"];
}]]);
} @catch (...) {
return false;
}
return true; return true;
} }
@@ -1505,58 +1470,31 @@
@"composingExtent" : @(-1), @"composingExtent" : @(-1),
}]; }];
NSDictionary* expectedState = @{
@"selectionBase" : @(4),
@"selectionExtent" : @(4),
@"selectionAffinity" : @"TextAffinity.upstream",
@"selectionIsDirectional" : @(NO),
@"composingBase" : @(-1),
@"composingExtent" : @(-1),
@"text" : @"Text",
};
NSData* updateCall = [[FlutterJSONMethodCodec sharedInstance]
encodeMethodCall:[FlutterMethodCall
methodCallWithMethodName:@"TextInputClient.updateEditingState"
arguments:@[ @(1), expectedState ]]];
OCMExpect( // NOLINT(google-objc-avoid-throwing-exception)
[binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]);
[plugin handleMethodCall:call [plugin handleMethodCall:call
result:^(id){ result:^(id){
}]; }];
@try { // Verify editing state was set.
OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) NSDictionary* editingState = [plugin editingState];
[binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]); EXPECT_STREQ([editingState[@"text"] UTF8String], "Text");
} @catch (...) { EXPECT_STREQ([editingState[@"selectionAffinity"] UTF8String], "TextAffinity.upstream");
return false; EXPECT_FALSE([editingState[@"selectionIsDirectional"] boolValue]);
} EXPECT_EQ([editingState[@"selectionBase"] intValue], 4);
EXPECT_EQ([editingState[@"selectionExtent"] intValue], 4);
EXPECT_EQ([editingState[@"composingBase"] intValue], -1);
EXPECT_EQ([editingState[@"composingExtent"] intValue], -1);
[plugin doCommandBySelector:@selector(insertNewline:)]; [plugin doCommandBySelector:@selector(insertNewline:)];
NSDictionary* updatedState = @{ // Verify editing state was set.
@"selectionBase" : @(5), editingState = [plugin editingState];
@"selectionExtent" : @(5), EXPECT_STREQ([editingState[@"text"] UTF8String], "Text\n");
@"selectionAffinity" : @"TextAffinity.upstream", EXPECT_STREQ([editingState[@"selectionAffinity"] UTF8String], "TextAffinity.upstream");
@"selectionIsDirectional" : @(NO), EXPECT_FALSE([editingState[@"selectionIsDirectional"] boolValue]);
@"composingBase" : @(-1), EXPECT_EQ([editingState[@"selectionBase"] intValue], 5);
@"composingExtent" : @(-1), EXPECT_EQ([editingState[@"selectionExtent"] intValue], 5);
@"text" : @"Text\n", EXPECT_EQ([editingState[@"composingBase"] intValue], -1);
}; EXPECT_EQ([editingState[@"composingExtent"] intValue], -1);
updateCall = [[FlutterJSONMethodCodec sharedInstance]
encodeMethodCall:[FlutterMethodCall
methodCallWithMethodName:@"TextInputClient.updateEditingState"
arguments:@[ @(1), updatedState ]]];
@try {
OCMVerify( // NOLINT(google-objc-avoid-throwing-exception)
[binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]);
} @catch (...) {
return false;
}
return true; return true;
} }