Unverified Commit 1bc787ee authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Fix dragging while the text selection toolbar is up doesn't hide toolbar (#106878)

Fixes a fidelity bug on desktop involving the selection toolbar not hiding when it should have.
parent 0c75ae1e
......@@ -969,7 +969,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
|| cause == SelectionChangedCause.drag) {
_editableText.bringIntoView(selection.extent);
}
return;
break;
case TargetPlatform.linux:
case TargetPlatform.windows:
case TargetPlatform.fuchsia:
......@@ -977,7 +977,21 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
if (cause == SelectionChangedCause.drag) {
_editableText.bringIntoView(selection.extent);
}
return;
break;
}
switch (defaultTargetPlatform) {
case TargetPlatform.iOS:
case TargetPlatform.fuchsia:
case TargetPlatform.android:
break;
case TargetPlatform.macOS:
case TargetPlatform.linux:
case TargetPlatform.windows:
if (cause == SelectionChangedCause.drag) {
_editableText.hideToolbar();
}
break;
}
}
......
......@@ -1063,7 +1063,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
|| cause == SelectionChangedCause.drag) {
_editableText?.bringIntoView(selection.extent);
}
return;
break;
case TargetPlatform.linux:
case TargetPlatform.windows:
case TargetPlatform.fuchsia:
......@@ -1071,7 +1071,21 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
if (cause == SelectionChangedCause.drag) {
_editableText?.bringIntoView(selection.extent);
}
return;
break;
}
switch (Theme.of(context).platform) {
case TargetPlatform.iOS:
case TargetPlatform.fuchsia:
case TargetPlatform.android:
break;
case TargetPlatform.macOS:
case TargetPlatform.linux:
case TargetPlatform.windows:
if (cause == SelectionChangedCause.drag) {
_editableText?.hideToolbar();
}
break;
}
}
......
......@@ -155,7 +155,6 @@ class PathPointsMatcher extends Matcher {
}
}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
final MockClipboard mockClipboard = MockClipboard();
......@@ -4080,6 +4079,53 @@ void main() {
expect(find.byType(CupertinoTextSelectionToolbar), findsOneWidget);
expect(tester.takeException(), null);
});
testWidgets('Drag selection hides the selection menu', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController(
text: 'blah1 blah2',
);
await tester.pumpWidget(
CupertinoApp(
home: Center(
child: CupertinoTextField(
controller: controller,
),
),
),
);
// Initially, the menu is not shown and there is no selection.
expect(controller.selection, const TextSelection(baseOffset: -1, extentOffset: -1));
final Offset midBlah1 = textOffsetToPosition(tester, 2);
final Offset midBlah2 = textOffsetToPosition(tester, 8);
// Right click the second word.
final TestGesture gesture = await tester.startGesture(
midBlah2,
kind: PointerDeviceKind.mouse,
buttons: kSecondaryMouseButton,
);
await tester.pump();
await gesture.up();
await tester.pumpAndSettle();
// The toolbar is shown.
expect(find.text('Paste'), findsOneWidget);
// Drag the mouse to the first word.
final TestGesture gesture2 = await tester.startGesture(
midBlah1,
kind: PointerDeviceKind.mouse,
);
await tester.pump();
await gesture2.moveTo(midBlah2);
await tester.pump();
await gesture2.up();
await tester.pumpAndSettle();
// The toolbar is hidden.
expect(find.text('Paste'), findsNothing);
}, variant: TargetPlatformVariant.desktop());
}, skip: isContextMenuProvidedByPlatform); // [intended] only applies to platforms where we supply the context menu.
group('textAlignVertical position', () {
......@@ -4509,6 +4555,7 @@ void main() {
},
);
});
testWidgets("Arrow keys don't move input focus", (WidgetTester tester) async {
final TextEditingController controller1 = TextEditingController();
final TextEditingController controller2 = TextEditingController();
......
......@@ -7658,6 +7658,56 @@ void main() {
skip: isContextMenuProvidedByPlatform, // [intended] only applies to platforms where we supply the context menu.,
);
testWidgets('Drag selection hides the selection menu', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController(
text: 'blah1 blah2',
);
await tester.pumpWidget(
MaterialApp(
home: Material(
child: TextField(
controller: controller,
),
),
),
);
// Initially, the menu is not shown and there is no selection.
expect(controller.selection, const TextSelection(baseOffset: -1, extentOffset: -1));
final Offset midBlah1 = textOffsetToPosition(tester, 2);
final Offset midBlah2 = textOffsetToPosition(tester, 8);
// Right click the second word.
final TestGesture gesture = await tester.startGesture(
midBlah2,
kind: PointerDeviceKind.mouse,
buttons: kSecondaryMouseButton,
);
await tester.pump();
await gesture.up();
await tester.pumpAndSettle();
// The toolbar is shown.
expect(find.text('Paste'), findsOneWidget);
// Drag the mouse to the first word.
final TestGesture gesture2 = await tester.startGesture(
midBlah1,
kind: PointerDeviceKind.mouse,
);
await tester.pump();
await gesture2.moveTo(midBlah2);
await tester.pump();
await gesture2.up();
await tester.pumpAndSettle();
// The toolbar is hidden.
expect(find.text('Paste'), findsNothing);
},
variant: TargetPlatformVariant.desktop(),
skip: isContextMenuProvidedByPlatform, // [intended] only applies to platforms where we supply the context menu.
);
testWidgets(
'Long press on an autofocused field shows the selection menu',
(WidgetTester tester) async {
......
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