AppFlowy/frontend/appflowy_flutter/integration_test/util/ime.dart
Mathias Mogensen acc03b8cc4
chore: code cleanup according to unintroduced lints (#4488)
* chore: remove redundant arguments

* chore: remove unused constructor params

* chore: reorganize constructors

* chore: remove unnecessary awaits in returns

* chore: remove unnecessary paranthesis

* chore: add lints

* chore: clean up after merge

* chore: add sort constructors first

* chore: organize constructors in blocs

* chore: use sizedbox.shrink over empty container
2024-01-25 23:37:36 +08:00

48 lines
1.3 KiB
Dart

import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
extension IME on WidgetTester {
IMESimulator get ime => IMESimulator(this);
}
class IMESimulator {
IMESimulator(this.tester) {
client = findTextInputClient();
}
final WidgetTester tester;
late final TextInputClient client;
Future<void> insertText(String text) async {
for (final c in text.characters) {
await insertCharacter(c);
}
}
Future<void> insertCharacter(String character) async {
final value = client.currentTextEditingValue;
if (value == null) {
assert(false);
return;
}
final text = value.text
.replaceRange(value.selection.start, value.selection.end, character);
final textEditingValue = TextEditingValue(
text: text,
selection: TextSelection.collapsed(
offset: value.selection.baseOffset + 1,
),
);
client.updateEditingValue(textEditingValue);
await tester.pumpAndSettle();
}
TextInputClient findTextInputClient() {
final finder = find.byType(KeyboardServiceWidget);
final KeyboardServiceWidgetState state = tester.state(finder);
return state.textInputService as TextInputClient;
}
}