[web] Changes to web keyboard selection shortcuts for more consistent behavior (#114264)
This commit is contained in:
parent
45c3b028ca
commit
9f23391733
@ -402,22 +402,16 @@ class DefaultTextEditingShortcuts extends StatelessWidget {
|
||||
SingleActivator(LogicalKeyboardKey.arrowLeft, alt: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowRight, alt: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowUp, alt: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowDown, shift: true, alt: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowLeft, shift: true, alt: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowRight, shift: true, alt: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowUp, shift: true, alt: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowDown, meta: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowLeft, meta: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowRight, meta: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowUp, meta: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowDown, shift: true, meta: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowLeft, shift: true, meta: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowRight, shift: true, meta: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowUp, shift: true, meta: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowDown, shift: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowLeft, shift: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowRight, shift: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowUp, shift: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.pageUp, shift: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.pageDown, shift: true): DoNothingAndStopPropagationTextIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.end, shift: true): DoNothingAndStopPropagationTextIntent(),
|
||||
@ -445,6 +439,8 @@ class DefaultTextEditingShortcuts extends StatelessWidget {
|
||||
const SingleActivator(LogicalKeyboardKey.escape): const DoNothingAndStopPropagationTextIntent(),
|
||||
const SingleActivator(LogicalKeyboardKey.tab): const DoNothingAndStopPropagationTextIntent(),
|
||||
const SingleActivator(LogicalKeyboardKey.tab, shift: true): const DoNothingAndStopPropagationTextIntent(),
|
||||
const SingleActivator(LogicalKeyboardKey.arrowDown, shift: true, alt: true): const DoNothingAndStopPropagationTextIntent(),
|
||||
const SingleActivator(LogicalKeyboardKey.arrowUp, shift: true, alt: true): const DoNothingAndStopPropagationTextIntent(),
|
||||
};
|
||||
|
||||
static Map<ShortcutActivator, Intent> get _shortcuts {
|
||||
|
@ -67,6 +67,8 @@ void main() {
|
||||
'0123456789ABCDEFGHIJ'
|
||||
'0123456789ABCDEFGHIJ'
|
||||
'0123456789ABCDEFGHIJ';
|
||||
|
||||
const String testVerticalText = '1\n2\n3\n4\n5\n6\n7\n8\n9';
|
||||
final TextEditingController controller = TextEditingController(text: testText);
|
||||
|
||||
final FocusNode focusNode = FocusNode();
|
||||
@ -2043,7 +2045,8 @@ void main() {
|
||||
}, variant: appleOnly);
|
||||
});
|
||||
|
||||
testWidgets('vertical movement', (WidgetTester tester) async {
|
||||
testWidgets('vertical movement outside of selection',
|
||||
(WidgetTester tester) async {
|
||||
controller.text = testText;
|
||||
controller.selection = const TextSelection.collapsed(
|
||||
offset: 0,
|
||||
@ -2052,6 +2055,10 @@ void main() {
|
||||
await tester.pumpWidget(buildEditableText());
|
||||
|
||||
for (final SingleActivator activator in allModifierVariants(LogicalKeyboardKey.arrowDown)) {
|
||||
// Skip for the shift shortcut since web accepts it.
|
||||
if (activator.shift) {
|
||||
continue;
|
||||
}
|
||||
await sendKeyCombination(tester, activator);
|
||||
await tester.pump();
|
||||
|
||||
@ -2201,4 +2208,102 @@ void main() {
|
||||
}, variant: appleOnly);
|
||||
|
||||
}, skip: !kIsWeb);// [intended] specific tests target web.
|
||||
|
||||
group('Web does accept', () {
|
||||
testWidgets('select up', (WidgetTester tester) async {
|
||||
const SingleActivator selectUp =
|
||||
SingleActivator(LogicalKeyboardKey.arrowUp, shift: true);
|
||||
controller.text = testVerticalText;
|
||||
controller.selection = const TextSelection.collapsed(
|
||||
offset: 5,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(buildEditableText());
|
||||
await sendKeyCombination(tester, selectUp);
|
||||
await tester.pump();
|
||||
|
||||
expect(controller.text, testVerticalText);
|
||||
expect(
|
||||
controller.selection,
|
||||
const TextSelection(
|
||||
baseOffset: 5,
|
||||
extentOffset: 3), // selection extends upwards from 5
|
||||
reason: selectUp.toString(),
|
||||
);
|
||||
}, variant: TargetPlatformVariant.desktop());
|
||||
|
||||
testWidgets('select down', (WidgetTester tester) async {
|
||||
const SingleActivator selectDown =
|
||||
SingleActivator(LogicalKeyboardKey.arrowDown, shift: true);
|
||||
controller.text = testVerticalText;
|
||||
controller.selection = const TextSelection.collapsed(
|
||||
offset: 5,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(buildEditableText());
|
||||
await sendKeyCombination(tester, selectDown);
|
||||
await tester.pump();
|
||||
|
||||
expect(controller.text, testVerticalText);
|
||||
expect(
|
||||
controller.selection,
|
||||
const TextSelection(
|
||||
baseOffset: 5,
|
||||
extentOffset: 7), // selection extends downwards from 5
|
||||
reason: selectDown.toString(),
|
||||
);
|
||||
}, variant: TargetPlatformVariant.desktop());
|
||||
|
||||
testWidgets('select all up', (WidgetTester tester) async {
|
||||
final bool isMacOS = defaultTargetPlatform == TargetPlatform.macOS;
|
||||
final SingleActivator selectAllUp = isMacOS
|
||||
? const SingleActivator(LogicalKeyboardKey.arrowUp,
|
||||
shift: true, meta: true)
|
||||
: const SingleActivator(LogicalKeyboardKey.arrowUp,
|
||||
shift: true, alt: true);
|
||||
controller.text = testVerticalText;
|
||||
controller.selection = const TextSelection.collapsed(
|
||||
offset: 5,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(buildEditableText());
|
||||
await sendKeyCombination(tester, selectAllUp);
|
||||
await tester.pump();
|
||||
|
||||
expect(controller.text, testVerticalText);
|
||||
expect(
|
||||
controller.selection,
|
||||
const TextSelection(
|
||||
baseOffset: 5,
|
||||
extentOffset: 0), // selection extends all the way up
|
||||
reason: selectAllUp.toString(),
|
||||
);
|
||||
}, variant: TargetPlatformVariant.desktop());
|
||||
|
||||
testWidgets('select all down', (WidgetTester tester) async {
|
||||
final bool isMacOS = defaultTargetPlatform == TargetPlatform.macOS;
|
||||
final SingleActivator selectAllDown = isMacOS
|
||||
? const SingleActivator(LogicalKeyboardKey.arrowDown,
|
||||
shift: true, meta: true)
|
||||
: const SingleActivator(LogicalKeyboardKey.arrowDown,
|
||||
shift: true, alt: true);
|
||||
controller.text = testVerticalText;
|
||||
controller.selection = const TextSelection.collapsed(
|
||||
offset: 5,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(buildEditableText());
|
||||
await sendKeyCombination(tester, selectAllDown);
|
||||
await tester.pump();
|
||||
|
||||
expect(controller.text, testVerticalText);
|
||||
expect(
|
||||
controller.selection,
|
||||
const TextSelection(
|
||||
baseOffset: 5,
|
||||
extentOffset: 17), // selection extends all the way down
|
||||
reason: selectAllDown.toString(),
|
||||
);
|
||||
}, variant: TargetPlatformVariant.desktop());
|
||||
}, skip: !kIsWeb); // [intended] specific tests target web.
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user