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.
This commit is contained in:
parent
f8f14c3897
commit
3b05d80622
@ -207,6 +207,10 @@ class DefaultTextEditingShortcuts extends Shortcuts {
|
||||
const SingleActivator(LogicalKeyboardKey.keyA, control: true): const SelectAllTextIntent(SelectionChangedCause.keyboard),
|
||||
const SingleActivator(LogicalKeyboardKey.keyZ, control: true): const UndoTextIntent(SelectionChangedCause.keyboard),
|
||||
const SingleActivator(LogicalKeyboardKey.keyZ, shift: true, control: true): const RedoTextIntent(SelectionChangedCause.keyboard),
|
||||
// These keys should go to the IME when a field is focused, not to other
|
||||
// Shortcuts.
|
||||
const SingleActivator(LogicalKeyboardKey.space): const DoNothingAndStopPropagationTextIntent(),
|
||||
const SingleActivator(LogicalKeyboardKey.enter): const DoNothingAndStopPropagationTextIntent(),
|
||||
};
|
||||
|
||||
// The following key combinations have no effect on text editing on this
|
||||
@ -328,6 +332,10 @@ class DefaultTextEditingShortcuts extends Shortcuts {
|
||||
const SingleActivator(LogicalKeyboardKey.keyA, meta: true): const SelectAllTextIntent(SelectionChangedCause.keyboard),
|
||||
const SingleActivator(LogicalKeyboardKey.keyZ, meta: true): const UndoTextIntent(SelectionChangedCause.keyboard),
|
||||
const SingleActivator(LogicalKeyboardKey.keyZ, shift: true, meta: true): const RedoTextIntent(SelectionChangedCause.keyboard),
|
||||
// These keys should go to the IME when a field is focused, not to other
|
||||
// Shortcuts.
|
||||
const SingleActivator(LogicalKeyboardKey.space): const DoNothingAndStopPropagationTextIntent(),
|
||||
const SingleActivator(LogicalKeyboardKey.enter): const DoNothingAndStopPropagationTextIntent(),
|
||||
// The following key combinations have no effect on text editing on this
|
||||
// platform:
|
||||
// * End
|
||||
@ -410,6 +418,7 @@ class DefaultTextEditingShortcuts extends Shortcuts {
|
||||
const SingleActivator(LogicalKeyboardKey.end, control: true): const DoNothingAndStopPropagationTextIntent(),
|
||||
const SingleActivator(LogicalKeyboardKey.home, control: true): const DoNothingAndStopPropagationTextIntent(),
|
||||
const SingleActivator(LogicalKeyboardKey.space): const DoNothingAndStopPropagationTextIntent(),
|
||||
const SingleActivator(LogicalKeyboardKey.enter): const DoNothingAndStopPropagationTextIntent(),
|
||||
const SingleActivator(LogicalKeyboardKey.keyX, control: true): const DoNothingAndStopPropagationTextIntent(),
|
||||
const SingleActivator(LogicalKeyboardKey.keyX, meta: true): const DoNothingAndStopPropagationTextIntent(),
|
||||
const SingleActivator(LogicalKeyboardKey.keyC, control: true): const DoNothingAndStopPropagationTextIntent(),
|
||||
|
@ -11474,6 +11474,48 @@ void main() {
|
||||
);
|
||||
}, variant: TargetPlatformVariant.all(), skip: kIsWeb); // [intended]
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/98322.
|
||||
testWidgets('EditableText consumes ActivateIntent and ButtonActivateIntent', (WidgetTester tester) async {
|
||||
bool receivedIntent = false;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Actions(
|
||||
actions: <Type, Action<Intent>>{
|
||||
ActivateIntent: CallbackAction<ActivateIntent>(onInvoke: (_) {
|
||||
receivedIntent = true;
|
||||
return;
|
||||
}),
|
||||
ButtonActivateIntent: CallbackAction<ActivateIntent>(onInvoke: (_) {
|
||||
receivedIntent = true;
|
||||
return;
|
||||
}),
|
||||
},
|
||||
child: EditableText(
|
||||
autofocus: true,
|
||||
backgroundCursorColor: Colors.blue,
|
||||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
style: textStyle,
|
||||
cursorColor: cursorColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pump();
|
||||
expect(focusNode.hasFocus, isTrue);
|
||||
|
||||
// ActivateIntent, which is triggered by space and enter in WidgetsApp, is
|
||||
// consumed by EditableText so that the space/enter reach the IME.
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.space);
|
||||
await tester.pump();
|
||||
expect(receivedIntent, isFalse);
|
||||
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.pump();
|
||||
expect(receivedIntent, isFalse);
|
||||
});
|
||||
}
|
||||
|
||||
class UnsettableController extends TextEditingController {
|
||||
|
Loading…
x
Reference in New Issue
Block a user