From 9a39a5d69795448e4ad939166080e8e921e435af Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Mon, 14 Aug 2023 15:51:05 -0700 Subject: [PATCH] Selection area should move selection word by word on a long press drag (#132518) On native iOS and Android when long pressing and then dragging the selection expands word by word. Before this change `SelectionArea` expanded the selection character by character on a long press drag. Fixes #104603 --- packages/flutter/lib/src/widgets/selectable_region.dart | 2 +- packages/flutter/test/widgets/selectable_region_test.dart | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/flutter/lib/src/widgets/selectable_region.dart b/packages/flutter/lib/src/widgets/selectable_region.dart index 33ca404dce..4b3d6e3730 100644 --- a/packages/flutter/lib/src/widgets/selectable_region.dart +++ b/packages/flutter/lib/src/widgets/selectable_region.dart @@ -529,7 +529,7 @@ class SelectableRegionState extends State with TextSelectionDe } void _handleTouchLongPressMoveUpdate(LongPressMoveUpdateDetails details) { - _selectEndTo(offset: details.globalPosition); + _selectEndTo(offset: details.globalPosition, textGranularity: TextGranularity.word); } void _handleTouchLongPressEnd(LongPressEndDetails details) { diff --git a/packages/flutter/test/widgets/selectable_region_test.dart b/packages/flutter/test/widgets/selectable_region_test.dart index f70a046a5c..2f70f266f9 100644 --- a/packages/flutter/test/widgets/selectable_region_test.dart +++ b/packages/flutter/test/widgets/selectable_region_test.dart @@ -338,6 +338,7 @@ void main() { expect(renderSelectionSpy.events[0].type, SelectionEventType.endEdgeUpdate); final SelectionEdgeUpdateEvent edgeEvent = renderSelectionSpy.events[0] as SelectionEdgeUpdateEvent; expect(edgeEvent.globalPosition, const Offset(200.0, 50.0)); + expect(edgeEvent.granularity, TextGranularity.word); }); testWidgets( @@ -1656,7 +1657,7 @@ void main() { await gesture.up(); }, skip: isBrowser); // https://github.com/flutter/flutter/issues/61020 - testWidgets('long press and drag touch selection', (WidgetTester tester) async { + testWidgets('long press and drag touch moves selection word by word', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( home: SelectableRegion( @@ -1681,9 +1682,9 @@ void main() { expect(paragraph1.selections[0], const TextSelection(baseOffset: 4, extentOffset: 7)); final RenderParagraph paragraph2 = tester.renderObject(find.descendant(of: find.text('Good, and you?'), matching: find.byType(RichText))); - await gesture.moveTo(textOffsetToPosition(paragraph2, 5)); + await gesture.moveTo(textOffsetToPosition(paragraph2, 7)); expect(paragraph1.selections[0], const TextSelection(baseOffset: 4, extentOffset: 12)); - expect(paragraph2.selections[0], const TextSelection(baseOffset: 0, extentOffset: 5)); + expect(paragraph2.selections[0], const TextSelection(baseOffset: 0, extentOffset: 9)); await gesture.up(); });