From 30846de3ec8df0d29661d3db82d7d8adac270fdd Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Thu, 17 Mar 2022 16:50:15 -0700 Subject: [PATCH] Material text selection menu should not show pointer cursor (#100248) --- .../src/material/desktop_text_selection.dart | 2 + .../test/material/text_field_test.dart | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/packages/flutter/lib/src/material/desktop_text_selection.dart b/packages/flutter/lib/src/material/desktop_text_selection.dart index ea620f1e23..dd92770bf7 100644 --- a/packages/flutter/lib/src/material/desktop_text_selection.dart +++ b/packages/flutter/lib/src/material/desktop_text_selection.dart @@ -332,6 +332,8 @@ class _DesktopTextSelectionToolbarButton extends StatelessWidget { child: TextButton( style: TextButton.styleFrom( alignment: Alignment.centerLeft, + enabledMouseCursor: SystemMouseCursors.basic, + disabledMouseCursor: SystemMouseCursors.basic, primary: primary, shape: const RoundedRectangleBorder(), minimumSize: const Size(kMinInteractiveDimension, 36.0), diff --git a/packages/flutter/test/material/text_field_test.dart b/packages/flutter/test/material/text_field_test.dart index 4a96ed2ae4..51f7b90dc6 100644 --- a/packages/flutter/test/material/text_field_test.dart +++ b/packages/flutter/test/material/text_field_test.dart @@ -10027,6 +10027,45 @@ void main() { await gesture.moveTo(center); }); + testWidgets('Text selection menu does not change mouse cursor when hovered', (WidgetTester tester) async { + final TextEditingController controller = TextEditingController( + text: 'Atwater Peel Sherbrooke Bonaventure', + ); + await tester.pumpWidget( + MaterialApp( + home: Material( + child: MouseRegion( + cursor: SystemMouseCursors.forbidden, + child: TextField( + controller: controller, + ), + ), + ), + ), + ); + + expect(find.text('Copy'), findsNothing); + + final TestGesture gesture = await tester.startGesture( + textOffsetToPosition(tester, 3), + kind: PointerDeviceKind.mouse, + buttons: kSecondaryMouseButton, + ); + addTearDown(gesture.removePointer); + await tester.pump(); + await gesture.up(); + await tester.pumpAndSettle(); + + expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text); + expect(find.text('Copy'), findsOneWidget); + + await gesture.moveTo(tester.getCenter(find.text('Copy'))); + expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic); + }, + variant: TargetPlatformVariant.desktop(), + skip: isContextMenuProvidedByPlatform, // [intended] only applies to platforms where we supply the context menu. + ); + testWidgets('Caret rtl with changing width', (WidgetTester tester) async { late StateSetter setState; bool isWide = false;