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
…tion (Resolves #1937)
  • Loading branch information
angelosilvestre committed May 20, 2024
1 parent cb836d7 commit e02b0a3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 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,22 +1384,33 @@ class SuperEditorAndroidControlsOverlayManagerState extends State<SuperEditorAnd
bool get wantsToDisplayMagnifier => _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();
}
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 e02b0a3

Please sign in to comment.