Hide toolbar after select all on desktop (#100261)

This commit is contained in:
Justin McCandless 2022-03-18 10:50:18 -07:00 committed by GitHub
parent 795fe375bc
commit a217bbb6de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 0 deletions

View File

@ -77,6 +77,12 @@ class _CupertinoDesktopTextSelectionControls extends TextSelectionControls {
Offset getHandleAnchor(TextSelectionHandleType type, double textLineHeight) {
return Offset.zero;
}
@override
void handleSelectAll(TextSelectionDelegate delegate) {
super.handleSelectAll(delegate);
delegate.hideToolbar();
}
}
/// Text selection controls that follows Mac design conventions.

View File

@ -73,6 +73,12 @@ class _DesktopTextSelectionControls extends TextSelectionControls {
value.text.isNotEmpty &&
!(value.selection.start == 0 && value.selection.end == value.text.length);
}
@override
void handleSelectAll(TextSelectionDelegate delegate) {
super.handleSelectAll(delegate);
delegate.hideToolbar();
}
}
/// Text selection controls that loosely follows Material design conventions.

View File

@ -10125,6 +10125,56 @@ void main() {
expect(cursorRight, inputWidth - kCaretGap);
});
testWidgets('Text selection menu hides after select all on desktop', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure',
);
await tester.pumpWidget(
MaterialApp(
home: Material(
child: TextField(
controller: controller,
),
),
),
);
final String selectAll = defaultTargetPlatform == TargetPlatform.macOS
? 'Select All'
: 'Select all';
expect(find.text(selectAll), findsNothing);
expect(find.text('Copy'), findsNothing);
final TestGesture gesture = await tester.startGesture(
const Offset(10.0, 0.0) + textOffsetToPosition(tester, controller.text.length),
kind: PointerDeviceKind.mouse,
buttons: kSecondaryMouseButton,
);
addTearDown(gesture.removePointer);
await tester.pump();
await gesture.up();
await tester.pumpAndSettle();
expect(
controller.value.selection,
TextSelection.collapsed(
offset: controller.text.length,
affinity: TextAffinity.upstream,
),
);
expect(find.text(selectAll), findsOneWidget);
await tester.tapAt(tester.getCenter(find.text(selectAll)));
await tester.pump();
expect(find.text(selectAll), findsNothing);
expect(find.text('Copy'), findsNothing);
},
variant: TargetPlatformVariant.desktop(),
skip: isContextMenuProvidedByPlatform, // [intended] only applies to platforms where we supply the context menu.
);
// Regressing test for https://github.com/flutter/flutter/issues/70625
testWidgets('TextFields can inherit [FloatingLabelBehaviour] from InputDecorationTheme.', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode();