Skip to content

Commit

Permalink
Hide text selection handle after entering text (flutter#37436)
Browse files Browse the repository at this point in the history
The text caret wasn't being hidden after entering text, this fixes it.
  • Loading branch information
justinmc authored Aug 2, 2019
1 parent 9553f8d commit 954714c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
3 changes: 0 additions & 3 deletions packages/flutter/lib/src/widgets/editable_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1657,9 +1657,6 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien

@override
void hideToolbar() {
if (_selectionOverlay == null || !_selectionOverlay.toolbarIsVisible) {
return;
}
_selectionOverlay?.hide();
}

Expand Down
40 changes: 40 additions & 0 deletions packages/flutter/test/material/text_field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,46 @@ void main() {
expect(handle.opacity.value, equals(1.0));
});

testWidgets('Entering text hides selection handle caret', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController();

await tester.pumpWidget(
overlay(
child: TextField(
controller: controller,
),
)
);

const String testValue = 'abcdefghi';
await tester.enterText(find.byType(TextField), testValue);
expect(controller.value.text, testValue);
await skipPastScrollingAnimation(tester);

// Handle not shown.
expect(controller.selection.isCollapsed, true);
final Finder fadeFinder = find.byType(FadeTransition);
expect(fadeFinder, findsNothing);

// Tap on the text field to show the handle.
await tester.tap(find.byType(TextField));
await tester.pumpAndSettle();
expect(controller.selection.isCollapsed, true);
expect(fadeFinder, findsNWidgets(1));
final FadeTransition handle = tester.widget(fadeFinder.at(0));
expect(handle.opacity.value, equals(1.0));

// Enter more text.
const String testValueAddition = 'jklmni';
await tester.enterText(find.byType(TextField), testValueAddition);
expect(controller.value.text, testValueAddition);
await skipPastScrollingAnimation(tester);

// Handle not shown.
expect(controller.selection.isCollapsed, true);
expect(fadeFinder, findsNothing);
});

testWidgets('Mouse long press is just like a tap', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController();

Expand Down

0 comments on commit 954714c

Please sign in to comment.