Unverified Commit ce4f15cd authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

Toggle toolbar exception fix (#34055)

Stop a text editing error from happening
parent 1157e674
...@@ -749,7 +749,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi ...@@ -749,7 +749,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
cause: SelectionChangedCause.forcePress, cause: SelectionChangedCause.forcePress,
); );
if (_shouldShowSelectionToolbar) { if (_shouldShowSelectionToolbar) {
_editableTextKey.currentState.toggleToolbar(); _editableTextKey.currentState.showToolbar();
} }
} }
} }
...@@ -819,7 +819,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi ...@@ -819,7 +819,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
void _handleSingleLongTapEnd(LongPressEndDetails details) { void _handleSingleLongTapEnd(LongPressEndDetails details) {
if (widget.selectionEnabled) { if (widget.selectionEnabled) {
if (_shouldShowSelectionToolbar) if (_shouldShowSelectionToolbar)
_editableTextKey.currentState.toggleToolbar(); _editableTextKey.currentState.showToolbar();
} }
} }
...@@ -827,7 +827,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi ...@@ -827,7 +827,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
if (widget.selectionEnabled) { if (widget.selectionEnabled) {
_renderEditable.selectWord(cause: SelectionChangedCause.doubleTap); _renderEditable.selectWord(cause: SelectionChangedCause.doubleTap);
if (_shouldShowSelectionToolbar) { if (_shouldShowSelectionToolbar) {
_editableText.toggleToolbar(); _editableText.showToolbar();
} }
} }
} }
......
...@@ -1482,11 +1482,12 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien ...@@ -1482,11 +1482,12 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
/// Shows the selection toolbar at the location of the current cursor. /// Shows the selection toolbar at the location of the current cursor.
/// ///
/// Returns `false` if a toolbar couldn't be shown such as when no text /// Returns `false` if a toolbar couldn't be shown, such as when the toolbar
/// selection currently exists. /// is already shown, or when no text selection currently exists.
bool showToolbar() { bool showToolbar() {
if (_selectionOverlay == null) if (_selectionOverlay == null || _selectionOverlay.toolbarIsVisible) {
return false; return false;
}
_selectionOverlay.showToolbar(); _selectionOverlay.showToolbar();
return true; return true;
......
...@@ -5221,7 +5221,7 @@ void main() { ...@@ -5221,7 +5221,7 @@ void main() {
); );
testWidgets( testWidgets(
'double double tap toggles selection menu', 'double double tap just shows the selection menu',
(WidgetTester tester) async { (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: '', text: '',
...@@ -5245,17 +5245,17 @@ void main() { ...@@ -5245,17 +5245,17 @@ void main() {
await tester.pump(); await tester.pump();
expect(find.text('PASTE'), findsOneWidget); expect(find.text('PASTE'), findsOneWidget);
// Double tap again hides the selection menu. // Double tap again keeps the selection menu visible.
await tester.tapAt(textOffsetToPosition(tester, 0)); await tester.tapAt(textOffsetToPosition(tester, 0));
await tester.pump(const Duration(milliseconds: 50)); await tester.pump(const Duration(milliseconds: 50));
await tester.tapAt(textOffsetToPosition(tester, 0)); await tester.tapAt(textOffsetToPosition(tester, 0));
await tester.pump(); await tester.pump();
expect(find.text('PASTE'), findsNWidgets(0)); expect(find.text('PASTE'), findsOneWidget);
}, },
); );
testWidgets( testWidgets(
'double long press toggles selection menu', 'double long press just shows the selection menu',
(WidgetTester tester) async { (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: '', text: '',
...@@ -5277,10 +5277,10 @@ void main() { ...@@ -5277,10 +5277,10 @@ void main() {
await tester.pump(); await tester.pump();
expect(find.text('PASTE'), findsOneWidget); expect(find.text('PASTE'), findsOneWidget);
// Double tap again hides the selection menu. // Long press again keeps the selection menu visible.
await tester.longPressAt(textOffsetToPosition(tester, 0)); await tester.longPressAt(textOffsetToPosition(tester, 0));
await tester.pump(); await tester.pump();
expect(find.text('PASTE'), findsNWidgets(0)); expect(find.text('PASTE'), findsOneWidget);
}, },
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment