Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 3b05d80

Browse files
authored
Spacebar and enter in EditableText work with Inkwells (#98469)
Fixes a bug especially with text fields in a ListTile where space and enter didn't work.
1 parent f8f14c3 commit 3b05d80

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

packages/flutter/lib/src/widgets/default_text_editing_shortcuts.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ class DefaultTextEditingShortcuts extends Shortcuts {
207207
const SingleActivator(LogicalKeyboardKey.keyA, control: true): const SelectAllTextIntent(SelectionChangedCause.keyboard),
208208
const SingleActivator(LogicalKeyboardKey.keyZ, control: true): const UndoTextIntent(SelectionChangedCause.keyboard),
209209
const SingleActivator(LogicalKeyboardKey.keyZ, shift: true, control: true): const RedoTextIntent(SelectionChangedCause.keyboard),
210+
// These keys should go to the IME when a field is focused, not to other
211+
// Shortcuts.
212+
const SingleActivator(LogicalKeyboardKey.space): const DoNothingAndStopPropagationTextIntent(),
213+
const SingleActivator(LogicalKeyboardKey.enter): const DoNothingAndStopPropagationTextIntent(),
210214
};
211215

212216
// The following key combinations have no effect on text editing on this
@@ -328,6 +332,10 @@ class DefaultTextEditingShortcuts extends Shortcuts {
328332
const SingleActivator(LogicalKeyboardKey.keyA, meta: true): const SelectAllTextIntent(SelectionChangedCause.keyboard),
329333
const SingleActivator(LogicalKeyboardKey.keyZ, meta: true): const UndoTextIntent(SelectionChangedCause.keyboard),
330334
const SingleActivator(LogicalKeyboardKey.keyZ, shift: true, meta: true): const RedoTextIntent(SelectionChangedCause.keyboard),
335+
// These keys should go to the IME when a field is focused, not to other
336+
// Shortcuts.
337+
const SingleActivator(LogicalKeyboardKey.space): const DoNothingAndStopPropagationTextIntent(),
338+
const SingleActivator(LogicalKeyboardKey.enter): const DoNothingAndStopPropagationTextIntent(),
331339
// The following key combinations have no effect on text editing on this
332340
// platform:
333341
// * End
@@ -410,6 +418,7 @@ class DefaultTextEditingShortcuts extends Shortcuts {
410418
const SingleActivator(LogicalKeyboardKey.end, control: true): const DoNothingAndStopPropagationTextIntent(),
411419
const SingleActivator(LogicalKeyboardKey.home, control: true): const DoNothingAndStopPropagationTextIntent(),
412420
const SingleActivator(LogicalKeyboardKey.space): const DoNothingAndStopPropagationTextIntent(),
421+
const SingleActivator(LogicalKeyboardKey.enter): const DoNothingAndStopPropagationTextIntent(),
413422
const SingleActivator(LogicalKeyboardKey.keyX, control: true): const DoNothingAndStopPropagationTextIntent(),
414423
const SingleActivator(LogicalKeyboardKey.keyX, meta: true): const DoNothingAndStopPropagationTextIntent(),
415424
const SingleActivator(LogicalKeyboardKey.keyC, control: true): const DoNothingAndStopPropagationTextIntent(),

packages/flutter/test/widgets/editable_text_test.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11474,6 +11474,48 @@ void main() {
1147411474
);
1147511475
}, variant: TargetPlatformVariant.all(), skip: kIsWeb); // [intended]
1147611476
});
11477+
11478+
// Regression test for https://github.com/flutter/flutter/issues/98322.
11479+
testWidgets('EditableText consumes ActivateIntent and ButtonActivateIntent', (WidgetTester tester) async {
11480+
bool receivedIntent = false;
11481+
await tester.pumpWidget(
11482+
MaterialApp(
11483+
home: Actions(
11484+
actions: <Type, Action<Intent>>{
11485+
ActivateIntent: CallbackAction<ActivateIntent>(onInvoke: (_) {
11486+
receivedIntent = true;
11487+
return;
11488+
}),
11489+
ButtonActivateIntent: CallbackAction<ActivateIntent>(onInvoke: (_) {
11490+
receivedIntent = true;
11491+
return;
11492+
}),
11493+
},
11494+
child: EditableText(
11495+
autofocus: true,
11496+
backgroundCursorColor: Colors.blue,
11497+
controller: controller,
11498+
focusNode: focusNode,
11499+
style: textStyle,
11500+
cursorColor: cursorColor,
11501+
),
11502+
),
11503+
),
11504+
);
11505+
11506+
await tester.pump();
11507+
expect(focusNode.hasFocus, isTrue);
11508+
11509+
// ActivateIntent, which is triggered by space and enter in WidgetsApp, is
11510+
// consumed by EditableText so that the space/enter reach the IME.
11511+
await tester.sendKeyEvent(LogicalKeyboardKey.space);
11512+
await tester.pump();
11513+
expect(receivedIntent, isFalse);
11514+
11515+
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
11516+
await tester.pump();
11517+
expect(receivedIntent, isFalse);
11518+
});
1147711519
}
1147811520

1147911521
class UnsettableController extends TextEditingController {

0 commit comments

Comments
 (0)