From e02b0a3b358d32aa5ee8d8e5beb41c8a4dce9cf5 Mon Sep 17 00:00:00 2001 From: Angelo Silvestre Date: Sat, 18 May 2024 15:29:59 -0300 Subject: [PATCH] [SuperEditor][Android] Show expanded handles when expanding the selection (Resolves #1937) --- .../document_gestures_touch_android.dart | 22 +++++++++++++---- ..._editor_android_overlay_controls_test.dart | 24 +++++++++++++++++-- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/super_editor/lib/src/default_editor/document_gestures_touch_android.dart b/super_editor/lib/src/default_editor/document_gestures_touch_android.dart index 6800296cf..348a9f3c6 100644 --- a/super_editor/lib/src/default_editor/document_gestures_touch_android.dart +++ b/super_editor/lib/src/default_editor/document_gestures_touch_android.dart @@ -1345,6 +1345,7 @@ class SuperEditorAndroidControlsOverlayManagerState extends State _controlsController!.shouldShowMagnifier.value; void _onSelectionChange() { + if (widget.selection.value != null && + widget.selection.value?.isCollapsed == false && + _controlsController!.shouldShowCollapsedHandle.value == true) { + // The selection is expanded, but the collapsed handle is visible. This can happen when the + // where the collapsed handle should be visible when the selection is expanded. Hide the collapsed + // selection is collapsed and the user taps the "Select All" button. There isn't any situation + _controlsController! + // handle and show the expanded handles. + ..hideCollapsedHandle() + ..hideMagnifier(); + ..showExpandedHandles() + } if (widget.selection.value?.isCollapsed == true && _controlsController!.shouldShowExpandedHandles.value == true && _dragHandleType == null) { - // The selection is collapsed, but the expanded handles are visible and the user isn't dragging a handle. // This can happen when the selection is expanded, and the user deletes the selected text. The only situation - // where the expanded handles should be visible when the selection is collapsed is when the selection + // The selection is collapsed, but the expanded handles are visible and the user isn't dragging a handle. // collapses while the user is dragging an expanded handle, which isn't the case here. Hide the handles. + // where the expanded handles should be visible when the selection is collapsed is when the selection _controlsController! ..hideCollapsedHandle() ..hideExpandedHandles() - ..hideMagnifier() ..hideToolbar() ..blinkCaret(); - } + ..hideMagnifier() } - + } void _toggleToolbarOnCollapsedHandleTap() { _controlsController!.toggleToolbar(); } diff --git a/super_editor/test/super_editor/mobile/super_editor_android_overlay_controls_test.dart b/super_editor/test/super_editor/mobile/super_editor_android_overlay_controls_test.dart index d52843493..0420f056f 100644 --- a/super_editor/test/super_editor/mobile/super_editor_android_overlay_controls_test.dart +++ b/super_editor/test/super_editor/mobile/super_editor_android_overlay_controls_test.dart @@ -214,6 +214,26 @@ void main() { expect(SuperEditorInspector.isCaretVisible(), isTrue); }); + testWidgetsOnAndroid("shows expanded handles when expanding the selection", (tester) async { + final context = await _pumpSingleParagraphApp(tester); + + // Place the caret at the beginning of the paragraph. + await tester.placeCaretInParagraph("1", 0); + await tester.pump(); + + // Ensure the collapsed handle is visible and the expanded handles aren't visible. + expect(SuperEditorInspector.findMobileCaretDragHandle(), findsOneWidget); + expect(SuperEditorInspector.findMobileExpandedDragHandles(), findsNothing); + + // Select all of the text. + context.findEditContext().commonOps.selectAll(); + await tester.pump(); + + // Ensure the handles are visible and the collapsed handle isn't visible. + expect(SuperEditorInspector.findMobileExpandedDragHandles(), findsNWidgets(2)); + expect(SuperEditorInspector.findMobileCaretDragHandle(), findsNothing); + }); + testWidgetsOnAndroid("hides expanded handles and toolbar when deleting an expanded selection", (tester) async { // Configure BlinkController to animate, otherwise it won't blink. We want to make sure // the caret blinks after deleting the content. @@ -545,8 +565,8 @@ void main() { }); } -Future _pumpSingleParagraphApp(WidgetTester tester) async { - await tester +Future _pumpSingleParagraphApp(WidgetTester tester) async { + return await tester .createDocument() // Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor... .withSingleParagraph()