Skip to content

Commit

Permalink
Android - add selection handle on collapsed selection
Browse files Browse the repository at this point in the history
  • Loading branch information
amantoux committed Jan 1, 2024
1 parent 5c77e83 commit 714b478
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
20 changes: 3 additions & 17 deletions packages/fleather/lib/src/widgets/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1265,11 +1265,6 @@ class RawEditorState extends EditorState
performSpellCheck(widget.controller.plainTextEditingValue.text);
}

bool _shouldShowSelectionHandles() {
return widget.showSelectionHandles &&
!widget.controller.selection.isCollapsed;
}

@override
void didUpdateWidget(RawEditor oldWidget) {
super.didUpdateWidget(oldWidget);
Expand Down Expand Up @@ -1306,11 +1301,7 @@ class RawEditorState extends EditorState
_selectionOverlay?.update(textEditingValue);
}

if (_shouldShowSelectionHandles()) {
_selectionOverlay?.showHandles();
} else {
_selectionOverlay?.hideHandles();
}
_selectionOverlay?.handlesVisible = widget.showSelectionHandles;

if (!shouldCreateInputConnection) {
closeConnectionIfNeeded();
Expand Down Expand Up @@ -1385,13 +1376,8 @@ class RawEditorState extends EditorState
} else {
_selectionOverlay!.update(textEditingValue);
}

if (_shouldShowSelectionHandles()) {
_selectionOverlay!.handlesVisible = widget.showSelectionHandles;
_selectionOverlay?.showHandles();
} else {
_selectionOverlay?.hideHandles();
}
_selectionOverlay!.handlesVisible = widget.showSelectionHandles;
_selectionOverlay!.showHandles();
}

// This will show the keyboard for all selection changes on the
Expand Down
17 changes: 17 additions & 0 deletions packages/fleather/test/widgets/editor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,23 @@ void main() {
const TypeMatcher<MaterialTextSelectionControls>());
}, [TargetPlatform.android]);

testWidgetsWithPlatform(
'show single selection handle when setting cursor position (Android)',
(tester) async {
final document = ParchmentDocument.fromJson([
{'insert': 'Some piece of text\n'}
]);
final editor =
EditorSandBox(tester: tester, document: document, autofocus: true);
await editor.pump();
await tester.tapAt(tester.getTopLeft(find.byType(FleatherEditor)) +
const Offset(30, 1));
tester.binding.scheduleWarmUpFrame();
await tester.pump();
final handleOverlays = find.byType(SelectionHandleOverlay);
expect(handleOverlays, findsOneWidget);
}, [TargetPlatform.android]);

testWidgets('dragging collapsed selection shows magnifier',
(tester) async {
final document = ParchmentDocument.fromJson([
Expand Down

0 comments on commit 714b478

Please sign in to comment.