Unverified Commit a832a720 authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

Handle privatecommand messages that pass no data (#112590)

Fixes an error in some text editors.
parent 8815f60a
......@@ -1877,7 +1877,9 @@ class TextInput {
final Map<String, dynamic> firstArg = args[1] as Map<String, dynamic>;
_currentConnection!._client.performPrivateCommand(
firstArg['action'] as String,
firstArg['data'] as Map<String, dynamic>,
firstArg['data'] == null
? <String, dynamic>{}
: firstArg['data'] as Map<String, dynamic>,
);
break;
case 'TextInputClient.updateFloatingCursor':
......
......@@ -562,6 +562,32 @@ void main() {
expect(client.latestMethodCall, 'performPrivateCommand');
});
test('TextInputClient performPrivateCommand method is called with no data at all', () async {
// Assemble a TextInputConnection so we can verify its change in state.
final FakeTextInputClient client = FakeTextInputClient(TextEditingValue.empty);
const TextInputConfiguration configuration = TextInputConfiguration();
TextInput.attach(client, configuration);
expect(client.latestMethodCall, isEmpty);
// Send performPrivateCommand message.
final ByteData? messageBytes = const JSONMessageCodec().encodeMessage(<String, dynamic>{
'args': <dynamic>[
1,
jsonDecode('{"action": "actionCommand"}'), // No `data` parameter.
],
'method': 'TextInputClient.performPrivateCommand',
});
await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
'flutter/textinput',
messageBytes,
(ByteData? _) {},
);
expect(client.latestMethodCall, 'performPrivateCommand');
expect(client.latestPrivateCommandData, <String, dynamic>{});
});
test('TextInputClient showAutocorrectionPromptRect method is called', () async {
// Assemble a TextInputConnection so we can verify its change in state.
final FakeTextInputClient client = FakeTextInputClient(TextEditingValue.empty);
......@@ -933,6 +959,7 @@ class FakeTextInputClient with TextInputClient {
String latestMethodCall = '';
final List<String> performedSelectors = <String>[];
late Map<String, dynamic>? latestPrivateCommandData;
@override
TextEditingValue currentTextEditingValue;
......@@ -946,8 +973,9 @@ class FakeTextInputClient with TextInputClient {
}
@override
void performPrivateCommand(String action, Map<String, dynamic> data) {
void performPrivateCommand(String action, Map<String, dynamic>? data) {
latestMethodCall = 'performPrivateCommand';
latestPrivateCommandData = data;
}
@override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment