Skip to content

Commit

Permalink
[SuperEditor][Android] Show expanded handles when expanding the selec…
Browse files Browse the repository at this point in the history
  • Loading branch information
angelosilvestre authored and quaaantumdev committed May 23, 2024
1 parent 0b8e3e5 commit 6ab2e00
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,7 @@ class SuperEditorAndroidControlsOverlayManagerState extends State<SuperEditorAnd
_controlsController = SuperEditorAndroidControlsScope.rootOf(context);
// TODO: Replace Cupertino aligner with a generic aligner because this code runs on Android.
_toolbarAligner = CupertinoPopoverToolbarAligner();
widget.selection.addListener(_onSelectionChange);
}

@override
Expand Down Expand Up @@ -1383,7 +1384,12 @@ class SuperEditorAndroidControlsOverlayManagerState extends State<SuperEditorAnd
bool get wantsToDisplayMagnifier => _controlsController!.shouldShowMagnifier.value;

void _onSelectionChange() {
if (widget.selection.value?.isCollapsed == true &&
final selection = widget.selection.value;
if (selection == null) {
return;
}

if (selection.isCollapsed &&
_controlsController!.shouldShowExpandedHandles.value == true &&
_dragHandleType == null) {
// The selection is collapsed, but the expanded handles are visible and the user isn't dragging a handle.
Expand All @@ -1397,6 +1403,17 @@ class SuperEditorAndroidControlsOverlayManagerState extends State<SuperEditorAnd
..hideToolbar()
..blinkCaret();
}

if (!selection.isCollapsed && _controlsController!.shouldShowCollapsedHandle.value == true) {
// The selection is expanded, but the collapsed handle is visible. This can happen when the
// selection is collapsed and the user taps the "Select All" button. There isn't any situation
// where the collapsed handle should be visible when the selection is expanded. Hide the collapsed
// handle and show the expanded handles.
_controlsController!
..hideCollapsedHandle()
..showExpandedHandles()
..hideMagnifier();
}
}

void _toggleToolbarOnCollapsedHandleTap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -545,8 +565,8 @@ void main() {
});
}

Future<void> _pumpSingleParagraphApp(WidgetTester tester) async {
await tester
Future<TestDocumentContext> _pumpSingleParagraphApp(WidgetTester tester) async {
return await tester
.createDocument()
// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor...
.withSingleParagraph()
Expand Down

0 comments on commit 6ab2e00

Please sign in to comment.