Unverified Commit 6ffcc9e5 authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

Hide the context menu on tap down (#126295)

Desktop text selection toolbar no longer flashes before closing.
parent 15a7e073
......@@ -2108,10 +2108,13 @@ class TextSelectionGestureDetectorBuilder {
switch (defaultTargetPlatform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
// On mobile platforms the selection is set on tap up.
editableText.hideToolbar(false);
case TargetPlatform.iOS:
// On mobile platforms the selection is set on tap up.
break;
case TargetPlatform.macOS:
editableText.hideToolbar();
// On macOS, a shift-tapped unfocused field expands from 0, not from the
// previous selection.
if (isShiftPressedValid) {
......@@ -2132,6 +2135,7 @@ class TextSelectionGestureDetectorBuilder {
renderEditable.selectPosition(cause: SelectionChangedCause.tap);
case TargetPlatform.linux:
case TargetPlatform.windows:
editableText.hideToolbar();
if (isShiftPressedValid) {
_extendSelection(details.globalPosition, SelectionChangedCause.tap);
return;
......@@ -2206,10 +2210,9 @@ class TextSelectionGestureDetectorBuilder {
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
editableText.hideToolbar();
break;
// On desktop platforms the selection is set on tap down.
case TargetPlatform.android:
editableText.hideToolbar();
if (isShiftPressedValid) {
_extendSelection(details.globalPosition, SelectionChangedCause.tap);
return;
......@@ -2217,7 +2220,6 @@ class TextSelectionGestureDetectorBuilder {
renderEditable.selectPosition(cause: SelectionChangedCause.tap);
editableText.showSpellCheckSuggestionsToolbar();
case TargetPlatform.fuchsia:
editableText.hideToolbar();
if (isShiftPressedValid) {
_extendSelection(details.globalPosition, SelectionChangedCause.tap);
return;
......
......@@ -9513,4 +9513,49 @@ void main() {
variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS }),
skip: kIsWeb, // [intended]
);
testWidgets('text selection toolbar is hidden on tap down', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController(
text: 'blah1 blah2',
);
await tester.pumpWidget(
CupertinoApp(
home: Center(
child: CupertinoTextField(
controller: controller,
),
),
),
);
expect(find.byType(CupertinoAdaptiveTextSelectionToolbar), findsNothing);
TestGesture gesture = await tester.startGesture(
textOffsetToPosition(tester, 8),
kind: PointerDeviceKind.mouse,
buttons: kSecondaryMouseButton,
);
await tester.pump();
await gesture.up();
await tester.pumpAndSettle();
expect(find.byType(CupertinoAdaptiveTextSelectionToolbar), findsOneWidget);
gesture = await tester.startGesture(
textOffsetToPosition(tester, 2),
kind: PointerDeviceKind.mouse,
);
await tester.pump();
// After the gesture is down but not up, the toolbar is already gone.
expect(find.byType(CupertinoAdaptiveTextSelectionToolbar), findsNothing);
await gesture.up();
await tester.pumpAndSettle();
expect(find.byType(CupertinoAdaptiveTextSelectionToolbar), findsNothing);
},
skip: isContextMenuProvidedByPlatform, // [intended] only applies to platforms where we supply the context menu.
variant: TargetPlatformVariant.all(excluding: <TargetPlatform>{ TargetPlatform.iOS }),
);
}
......@@ -16315,6 +16315,53 @@ void main() {
expectedConfiguration.spellCheckSuggestionsToolbarBuilder,
);
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.iOS }));
testWidgets('text selection toolbar is hidden on tap down', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController(
text: 'blah1 blah2',
);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: TextField(
controller: controller,
),
),
),
),
);
expect(find.byType(AdaptiveTextSelectionToolbar), findsNothing);
TestGesture gesture = await tester.startGesture(
textOffsetToPosition(tester, 8),
kind: PointerDeviceKind.mouse,
buttons: kSecondaryMouseButton,
);
await tester.pump();
await gesture.up();
await tester.pumpAndSettle();
expect(find.byType(AdaptiveTextSelectionToolbar), findsOneWidget);
gesture = await tester.startGesture(
textOffsetToPosition(tester, 2),
kind: PointerDeviceKind.mouse,
);
await tester.pump();
// After the gesture is down but not up, the toolbar is already gone.
expect(find.byType(AdaptiveTextSelectionToolbar), findsNothing);
await gesture.up();
await tester.pumpAndSettle();
expect(find.byType(AdaptiveTextSelectionToolbar), findsNothing);
},
skip: isContextMenuProvidedByPlatform, // [intended] only applies to platforms where we supply the context menu.
variant: TargetPlatformVariant.all(excluding: <TargetPlatform>{ TargetPlatform.iOS }),
);
}
/// A Simple widget for testing the obscure text.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment