Clear the selection when a text widget loses focus (#10938)
Fixes https://github.com/flutter/flutter/issues/10911
This commit is contained in:
parent
128967cd2a
commit
856115b7e2
@ -531,6 +531,10 @@ class EditableTextState extends State<EditableText> implements TextInputClient {
|
|||||||
_openOrCloseInputConnectionIfNeeded();
|
_openOrCloseInputConnectionIfNeeded();
|
||||||
_startOrStopCursorTimerIfNeeded();
|
_startOrStopCursorTimerIfNeeded();
|
||||||
_updateOrDisposeSelectionOverlayIfNeeded();
|
_updateOrDisposeSelectionOverlayIfNeeded();
|
||||||
|
if (!_hasFocus) {
|
||||||
|
// Clear the selection and composition state if this widget lost focus.
|
||||||
|
_value = new TextEditingValue(text: _value.text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1503,4 +1503,41 @@ void main() {
|
|||||||
expect(scrollableState.position.pixels, isNot(equals(0.0)));
|
expect(scrollableState.position.pixels, isNot(equals(0.0)));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'Text field drops selection when losing focus',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
final Key key1 = new UniqueKey();
|
||||||
|
final TextEditingController controller1 = new TextEditingController();
|
||||||
|
final Key key2 = new UniqueKey();
|
||||||
|
|
||||||
|
Widget builder() {
|
||||||
|
return overlay(new Center(
|
||||||
|
child: new Material(
|
||||||
|
child: new Column(
|
||||||
|
children: <Widget>[
|
||||||
|
new TextField(
|
||||||
|
key: key1,
|
||||||
|
controller: controller1
|
||||||
|
),
|
||||||
|
new TextField(key: key2),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
await tester.pumpWidget(builder());
|
||||||
|
await tester.tap(find.byKey(key1));
|
||||||
|
await tester.enterText(find.byKey(key1), 'abcd');
|
||||||
|
await tester.pump();
|
||||||
|
controller1.selection = const TextSelection(baseOffset: 0, extentOffset: 3);
|
||||||
|
await tester.pump();
|
||||||
|
expect(controller1.selection, isNot(equals(TextRange.empty)));
|
||||||
|
|
||||||
|
await tester.tap(find.byKey(key2));
|
||||||
|
await tester.pump();
|
||||||
|
expect(controller1.selection, equals(TextRange.empty));
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user