Desktop platforms should not collapse selection on copy (#104209)
* Add tests * fix tests * updates Co-authored-by: Renzo Olivares <roliv@google.com>
This commit is contained in:
@@ -1693,12 +1693,12 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
|
||||
|
||||
switch (defaultTargetPlatform) {
|
||||
case TargetPlatform.iOS:
|
||||
break;
|
||||
case TargetPlatform.macOS:
|
||||
case TargetPlatform.android:
|
||||
case TargetPlatform.fuchsia:
|
||||
case TargetPlatform.linux:
|
||||
case TargetPlatform.windows:
|
||||
break;
|
||||
case TargetPlatform.android:
|
||||
case TargetPlatform.fuchsia:
|
||||
// Collapse the selection and hide the toolbar and handles.
|
||||
userUpdateTextEditingValue(
|
||||
TextEditingValue(
|
||||
|
||||
@@ -248,7 +248,7 @@ void main() {
|
||||
await tester.tap(find.text('Copy'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.text, 'blah1 blah2');
|
||||
expect(controller.selection, const TextSelection(baseOffset: 5, extentOffset: 5));
|
||||
expect(controller.selection, const TextSelection(baseOffset: 0, extentOffset: 5));
|
||||
expect(find.byType(CupertinoButton), findsNothing);
|
||||
|
||||
// Paste it at the end.
|
||||
|
||||
@@ -250,7 +250,7 @@ void main() {
|
||||
await tester.tap(find.text('Copy'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.text, 'blah1 blah2');
|
||||
expect(controller.selection, const TextSelection(baseOffset: 5, extentOffset: 5));
|
||||
expect(controller.selection, const TextSelection(baseOffset: 0, extentOffset: 5));
|
||||
expect(find.byType(CupertinoButton), findsNothing);
|
||||
|
||||
// Paste it at the end.
|
||||
@@ -359,7 +359,7 @@ void main() {
|
||||
await tester.tap(find.text('Copy'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.text, 'blah1 blah2');
|
||||
expect(controller.selection, const TextSelection(baseOffset: 5, extentOffset: 5));
|
||||
expect(controller.selection, const TextSelection(baseOffset: 0, extentOffset: 5));
|
||||
expect(find.byType(CupertinoButton), findsNothing);
|
||||
|
||||
// Paste it at the end.
|
||||
|
||||
@@ -65,7 +65,7 @@ void main() {
|
||||
await tester.tap(find.text('Copy'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.text, 'blah1 blah2');
|
||||
expect(controller.selection, const TextSelection(baseOffset: 5, extentOffset: 5));
|
||||
expect(controller.selection, const TextSelection(baseOffset: 0, extentOffset: 5));
|
||||
expect(find.byType(CupertinoButton), findsNothing);
|
||||
|
||||
// Paste it at the end.
|
||||
@@ -176,7 +176,7 @@ void main() {
|
||||
await tester.tap(find.text('Copy'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.text, 'blah1 blah2');
|
||||
expect(controller.selection, const TextSelection(baseOffset: 5, extentOffset: 5));
|
||||
expect(controller.selection, const TextSelection(baseOffset: 0, extentOffset: 5));
|
||||
expect(find.byType(CupertinoButton), findsNothing);
|
||||
|
||||
// Paste it at the end.
|
||||
|
||||
@@ -1553,6 +1553,82 @@ void main() {
|
||||
expect(find.text('Paste'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Copy selection does not collapse selection on desktop and iOS', (WidgetTester tester) async {
|
||||
final TextEditingController localController = TextEditingController(text: 'Hello world');
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: EditableText(
|
||||
backgroundCursorColor: Colors.grey,
|
||||
controller: localController,
|
||||
focusNode: focusNode,
|
||||
style: textStyle,
|
||||
cursorColor: cursorColor,
|
||||
selectionControls: materialTextSelectionControls,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final EditableTextState state =
|
||||
tester.state<EditableTextState>(find.byType(EditableText));
|
||||
|
||||
// Show the toolbar.
|
||||
state.renderEditable.selectWordsInRange(
|
||||
from: Offset.zero,
|
||||
cause: SelectionChangedCause.tap,
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
final TextSelection copySelectionRange = localController.selection;
|
||||
|
||||
state.showToolbar();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Copy'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Copy'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(copySelectionRange, localController.selection);
|
||||
expect(find.text('Copy'), findsNothing);
|
||||
}, skip: kIsWeb, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS, TargetPlatform.linux, TargetPlatform.windows })); // [intended]
|
||||
|
||||
testWidgets('Copy selection collapses selection and hides the toolbar on Android and Fuchsia', (WidgetTester tester) async {
|
||||
final TextEditingController localController = TextEditingController(text: 'Hello world');
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: EditableText(
|
||||
backgroundCursorColor: Colors.grey,
|
||||
controller: localController,
|
||||
focusNode: focusNode,
|
||||
style: textStyle,
|
||||
cursorColor: cursorColor,
|
||||
selectionControls: materialTextSelectionControls,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final EditableTextState state =
|
||||
tester.state<EditableTextState>(find.byType(EditableText));
|
||||
|
||||
// Show the toolbar.
|
||||
state.renderEditable.selectWordsInRange(
|
||||
from: Offset.zero,
|
||||
cause: SelectionChangedCause.tap,
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
final TextSelection copySelectionRange = localController.selection;
|
||||
|
||||
state.showToolbar();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Copy'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Copy'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(localController.selection, TextSelection.collapsed(offset: copySelectionRange.extentOffset));
|
||||
expect(find.text('Copy'), findsNothing);
|
||||
}, skip: kIsWeb, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.fuchsia })); // [intended]
|
||||
|
||||
testWidgets('can show the toolbar after clearing all text', (WidgetTester tester) async {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/35998.
|
||||
await tester.pumpWidget(
|
||||
|
||||
Reference in New Issue
Block a user