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
cause: SelectionChangedCause.forcePress,
);
if (_shouldShowSelectionToolbar) {
_editableTextKey.currentState.toggleToolbar();
_editableTextKey.currentState.showToolbar();
}
}
}
......@@ -819,7 +819,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
void _handleSingleLongTapEnd(LongPressEndDetails details) {
if (widget.selectionEnabled) {
if (_shouldShowSelectionToolbar)
_editableTextKey.currentState.toggleToolbar();
_editableTextKey.currentState.showToolbar();
}
}
......@@ -827,7 +827,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
if (widget.selectionEnabled) {
_renderEditable.selectWord(cause: SelectionChangedCause.doubleTap);
if (_shouldShowSelectionToolbar) {
_editableText.toggleToolbar();
_editableText.showToolbar();
}
}
}
......
......@@ -1482,11 +1482,12 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
/// 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
/// selection currently exists.
/// Returns `false` if a toolbar couldn't be shown, such as when the toolbar
/// is already shown, or when no text selection currently exists.
bool showToolbar() {
if (_selectionOverlay == null)
if (_selectionOverlay == null || _selectionOverlay.toolbarIsVisible) {
return false;
}
_selectionOverlay.showToolbar();
return true;
......
......@@ -5221,7 +5221,7 @@ void main() {
);
testWidgets(
'double double tap toggles selection menu',
'double double tap just shows the selection menu',
(WidgetTester tester) async {
final TextEditingController controller = TextEditingController(
text: '',
......@@ -5245,17 +5245,17 @@ void main() {
await tester.pump();
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.pump(const Duration(milliseconds: 50));
await tester.tapAt(textOffsetToPosition(tester, 0));
await tester.pump();
expect(find.text('PASTE'), findsNWidgets(0));
expect(find.text('PASTE'), findsOneWidget);
},
);
testWidgets(
'double long press toggles selection menu',
'double long press just shows the selection menu',
(WidgetTester tester) async {
final TextEditingController controller = TextEditingController(
text: '',
......@@ -5277,10 +5277,10 @@ void main() {
await tester.pump();
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.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