Unverified Commit b73722b1 authored by J-P Nurmi's avatar J-P Nurmi Committed by GitHub

[text_input] prepare for custom text input sources (#72803)

parent 58301211
......@@ -2038,7 +2038,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
void _closeInputConnectionIfNeeded() {
if (_hasInputConnection) {
_textInputConnection!.close();
TextInput.detach(this);
_textInputConnection = null;
_lastKnownRemoteTextEditingValue = null;
}
......@@ -2056,7 +2056,6 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
@override
void connectionClosed() {
if (_hasInputConnection) {
_textInputConnection!.connectionClosedReceived();
_textInputConnection = null;
_lastKnownRemoteTextEditingValue = null;
_finalizeEditing(TextInputAction.done, shouldUnfocus: true);
......
......@@ -22,6 +22,7 @@ void main() {
});
tearDown(() {
TextInput.reset();
TextInputConnection.debugResetId();
TextInput.setChannel(SystemChannels.textInput);
});
......@@ -74,6 +75,65 @@ void main() {
}),
]);
});
test('text input client is requested to hide on detach', () async {
final FakeTextInputClient client = FakeTextInputClient(TextEditingValue.empty);
TextInput.attach(client, client.configuration);
fakeTextChannel.validateOutgoingMethodCalls(<MethodCall>[
MethodCall('TextInput.setClient', <dynamic>[1, client.configuration.toJson()]),
]);
TextInput.detach(client);
fakeTextChannel.validateOutgoingMethodCalls(<MethodCall>[
// From original attach
MethodCall('TextInput.setClient', <dynamic>[1, client.configuration.toJson()]),
// From detach
const MethodCall('TextInput.clearClient'),
]);
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized() as TestWidgetsFlutterBinding;
await binding.runAsync(() async {});
await expectLater(fakeTextChannel.outgoingCalls.length, 3);
fakeTextChannel.validateOutgoingMethodCalls(<MethodCall>[
// From original attach
MethodCall('TextInput.setClient', <dynamic>[1, client.configuration.toJson()]),
// From detach
const MethodCall('TextInput.clearClient'),
// From hide
const MethodCall('TextInput.hide'),
]);
});
test('old client is detached when a new client is attached',() {
final FakeTextInputClient client1 = FakeTextInputClient(const TextEditingValue(text: '1'));
final TextInputConnection connection1 = TextInput.attach(client1, client1.configuration);
expect(connection1.attached, isTrue);
fakeTextChannel.validateOutgoingMethodCalls(<MethodCall>[
MethodCall('TextInput.setClient', <dynamic>[1, client1.configuration.toJson()]),
]);
final FakeTextInputClient client2 = FakeTextInputClient(const TextEditingValue(text: '1'));
final TextInputConnection connection2 = TextInput.attach(client2, client2.configuration);
expect(connection2.attached, isTrue);
expect(connection1.attached, isFalse);
fakeTextChannel.validateOutgoingMethodCalls(<MethodCall>[
// From original attach
MethodCall('TextInput.setClient', <dynamic>[1, client1.configuration.toJson()]),
// From internal detach
const MethodCall('TextInput.clearClient'),
// From second attach
MethodCall('TextInput.setClient', <dynamic>[2, client1.configuration.toJson()]),
]);
});
test('text input connection is reset', () async {
final FakeTextInputClient client = FakeTextInputClient(TextEditingValue.empty);
final TextInputConnection connection = TextInput.attach(client, client.configuration);
expect(connection.attached, isTrue);
TextInput.reset();
expect(connection.attached, isFalse);
});
});
group('TextInputConfiguration', () {
......
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