Skip to content

Commit

Permalink
[macOS] Do not bounce editing state back to framework on setEditState (
Browse files Browse the repository at this point in the history
…#42091)

Some context for this change flutter/flutter#118642 (comment) and flutter/flutter#118759 (comment) . 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](flutter/flutter#118759) and [#118642](flutter/flutter#118642)
  • Loading branch information
Renzo-Olivares committed May 26, 2023
1 parent 3b5b5fc commit 795db50
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -448,19 +448,6 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
} else if ([method isEqualToString:kSetEditingStateMethod]) {
NSDictionary* state = call.arguments;
[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]) {
NSDictionary* state = call.arguments;
[self setEditableTransform:state[kTransformKey]];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,34 +87,19 @@ - (bool)testEmptyCompositionRange {
@"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
result:^(id){
}];

@try {
OCMVerify( // NOLINT(google-objc-avoid-throwing-exception)
[binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]);
} @catch (...) {
return false;
}
// Verify editing state was set.
NSDictionary* editingState = [plugin editingState];
EXPECT_STREQ([editingState[@"text"] UTF8String], "Text");
EXPECT_STREQ([editingState[@"selectionAffinity"] UTF8String], "TextAffinity.upstream");
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;
}

Expand Down Expand Up @@ -298,30 +283,15 @@ - (bool)testComposingRegionRemovedByFramework {
result:^(id){
}];

NSDictionary* expectedState = @{
@"selectionBase" : @(2),
@"selectionExtent" : @(2),
@"selectionAffinity" : @"TextAffinity.upstream",
@"selectionIsDirectional" : @(NO),
@"composingBase" : @(-1),
@"composingExtent" : @(-1),
@"text" : @"Te",
};

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;
}
// Verify editing state was set.
NSDictionary* editingState = [plugin editingState];
EXPECT_STREQ([editingState[@"text"] UTF8String], "Te");
EXPECT_STREQ([editingState[@"selectionAffinity"] UTF8String], "TextAffinity.upstream");
EXPECT_FALSE([editingState[@"selectionIsDirectional"] boolValue]);
EXPECT_EQ([editingState[@"selectionBase"] intValue], 2);
EXPECT_EQ([editingState[@"selectionExtent"] intValue], 2);
EXPECT_EQ([editingState[@"composingBase"] intValue], -1);
EXPECT_EQ([editingState[@"composingExtent"] intValue], -1);
return true;
}

Expand Down Expand Up @@ -902,20 +872,15 @@ - (bool)testSetEditingStateWithTextEditingDelta {
result:^(id){
}];

// The setEditingState call is ACKed back to the framework.
@try {
OCMVerify( // NOLINT(google-objc-avoid-throwing-exception)
[binaryMessengerMock
sendOnChannel:@"flutter/textinput"
message:[OCMArg checkWithBlock:^BOOL(NSData* callData) {
FlutterMethodCall* call =
[[FlutterJSONMethodCodec sharedInstance] decodeMethodCall:callData];
return [[call method]
isEqualToString:@"TextInputClient.updateEditingStateWithDeltas"];
}]]);
} @catch (...) {
return false;
}
// Verify editing state was set.
NSDictionary* editingState = [plugin editingState];
EXPECT_STREQ([editingState[@"text"] UTF8String], "Text");
EXPECT_STREQ([editingState[@"selectionAffinity"] UTF8String], "TextAffinity.upstream");
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;
}

Expand Down Expand Up @@ -1505,58 +1470,31 @@ - (bool)testInsertNewLine {
@"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
result:^(id){
}];

@try {
OCMVerify( // NOLINT(google-objc-avoid-throwing-exception)
[binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]);
} @catch (...) {
return false;
}
// Verify editing state was set.
NSDictionary* editingState = [plugin editingState];
EXPECT_STREQ([editingState[@"text"] UTF8String], "Text");
EXPECT_STREQ([editingState[@"selectionAffinity"] UTF8String], "TextAffinity.upstream");
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:)];

NSDictionary* updatedState = @{
@"selectionBase" : @(5),
@"selectionExtent" : @(5),
@"selectionAffinity" : @"TextAffinity.upstream",
@"selectionIsDirectional" : @(NO),
@"composingBase" : @(-1),
@"composingExtent" : @(-1),
@"text" : @"Text\n",
};

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;
}
// Verify editing state was set.
editingState = [plugin editingState];
EXPECT_STREQ([editingState[@"text"] UTF8String], "Text\n");
EXPECT_STREQ([editingState[@"selectionAffinity"] UTF8String], "TextAffinity.upstream");
EXPECT_FALSE([editingState[@"selectionIsDirectional"] boolValue]);
EXPECT_EQ([editingState[@"selectionBase"] intValue], 5);
EXPECT_EQ([editingState[@"selectionExtent"] intValue], 5);
EXPECT_EQ([editingState[@"composingBase"] intValue], -1);
EXPECT_EQ([editingState[@"composingExtent"] intValue], -1);

return true;
}
Expand Down

0 comments on commit 795db50

Please sign in to comment.