Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions lib/src/keyboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,16 @@ extension KeyboardInput on WidgetTester {

/// Simulates the user pressing ENTER in a widget attached to the IME.
///
/// Instead of key events, this method generates a "\n" insertion followed by a TextInputAction.newline.
/// Instead of key events, this method generates a `\n` insertion followed by a `TextInputAction.newline`.
///
/// {@template newline_quirks_mode}
/// WARNING: On Android Web, and seemingly only Android Web, we've observed that the standard behavior is
/// to send a newline `\n`, but not a `TextInputAction.newline`. Because this behavior is an outlier, we believe
/// it's likely some kind of bug. Rather than always implement this behavior for Android Web, this method
/// has a [useQuirksMode] parameter. When [useQuirksMode] is `true`, no `TextInputAction.newline` is dispatched
/// for Android Web, but when its `false`, a `\n` AND a `TextInputAction.newline` are both dispatched, regardless
/// of platform.
/// {@endtemplate}
///
/// {@template ime_client_getter}
/// The given [finder] must find a [StatefulWidget] whose [State] implements
Expand All @@ -102,6 +111,7 @@ extension KeyboardInput on WidgetTester {
GetDeltaTextInputClient? getter,
bool settle = true,
int extraPumps = 0,
bool useQuirksMode = true,
}) async {
if (!testTextInput.hasAnyClients) {
// There isn't any IME connections.
Expand All @@ -110,8 +120,15 @@ extension KeyboardInput on WidgetTester {

await ime.typeText('\n', finder: finder, getter: getter);
await pump();
await testTextInput.receiveAction(TextInputAction.newline);
await pump();

// On any platform, except Android Web, we want to dispatch `TextInputAction.newline`
// in addition to the newline `\n`. However, on Android Web, when quirks mode is
// activated, we don't want to send a `TextInputAction.newline` because we've observed
// that in the real world, Android Web doesn't dispatch a `TextInputAction.newline`.
if (_keyEventPlatform != "android" || !kIsWeb || !useQuirksMode) {
await testTextInput.receiveAction(TextInputAction.newline);
await pump();
}
Comment on lines +128 to +131
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this won't work for regular tests, because kIsWeb cannot be overwritten. In super_editor, we use a separate getter that we can override at runtime.


await _maybeSettleOrExtraPumps(settle: settle, extraPumps: extraPumps);
}
Expand All @@ -122,12 +139,17 @@ extension KeyboardInput on WidgetTester {
/// then this method simulates pressing the newline action button on a software keyboard, which inserts "/n"
/// into the text, and also sends a NEWLINE action to the IME client.
///
/// Pressing ENTER through the IME has some quirks:
///
/// {@macro newline_quirks_mode}
///
/// {@macro ime_client_getter}
Future<void> pressEnterAdaptive({
Finder? finder,
GetDeltaTextInputClient? getter,
bool settle = true,
int extraPumps = 0,
bool useQuirksMode = true,
}) async {
final handled = await sendKeyEvent(LogicalKeyboardKey.enter, platform: _keyEventPlatform);
if (handled) {
Expand All @@ -137,7 +159,13 @@ extension KeyboardInput on WidgetTester {
return;
}

await pressEnterWithIme(finder: finder, getter: getter, settle: settle, extraPumps: extraPumps);
await pressEnterWithIme(
finder: finder,
getter: getter,
settle: settle,
extraPumps: extraPumps,
useQuirksMode: useQuirksMode,
);
}

/// Simulates pressing the SPACE key.
Expand Down