Unverified Commit 9a39a5d6 authored by Renzo Olivares's avatar Renzo Olivares Committed by GitHub

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
parent 0a10359f
...@@ -529,7 +529,7 @@ class SelectableRegionState extends State<SelectableRegion> with TextSelectionDe ...@@ -529,7 +529,7 @@ class SelectableRegionState extends State<SelectableRegion> with TextSelectionDe
} }
void _handleTouchLongPressMoveUpdate(LongPressMoveUpdateDetails details) { void _handleTouchLongPressMoveUpdate(LongPressMoveUpdateDetails details) {
_selectEndTo(offset: details.globalPosition); _selectEndTo(offset: details.globalPosition, textGranularity: TextGranularity.word);
} }
void _handleTouchLongPressEnd(LongPressEndDetails details) { void _handleTouchLongPressEnd(LongPressEndDetails details) {
......
...@@ -338,6 +338,7 @@ void main() { ...@@ -338,6 +338,7 @@ void main() {
expect(renderSelectionSpy.events[0].type, SelectionEventType.endEdgeUpdate); expect(renderSelectionSpy.events[0].type, SelectionEventType.endEdgeUpdate);
final SelectionEdgeUpdateEvent edgeEvent = renderSelectionSpy.events[0] as SelectionEdgeUpdateEvent; final SelectionEdgeUpdateEvent edgeEvent = renderSelectionSpy.events[0] as SelectionEdgeUpdateEvent;
expect(edgeEvent.globalPosition, const Offset(200.0, 50.0)); expect(edgeEvent.globalPosition, const Offset(200.0, 50.0));
expect(edgeEvent.granularity, TextGranularity.word);
}); });
testWidgets( testWidgets(
...@@ -1656,7 +1657,7 @@ void main() { ...@@ -1656,7 +1657,7 @@ void main() {
await gesture.up(); await gesture.up();
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/61020 }, 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( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: SelectableRegion( home: SelectableRegion(
...@@ -1681,9 +1682,9 @@ void main() { ...@@ -1681,9 +1682,9 @@ void main() {
expect(paragraph1.selections[0], const TextSelection(baseOffset: 4, extentOffset: 7)); expect(paragraph1.selections[0], const TextSelection(baseOffset: 4, extentOffset: 7));
final RenderParagraph paragraph2 = tester.renderObject<RenderParagraph>(find.descendant(of: find.text('Good, and you?'), matching: find.byType(RichText))); final RenderParagraph paragraph2 = tester.renderObject<RenderParagraph>(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(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(); await gesture.up();
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment