Unverified Commit 046d907f authored by Bruno Leroux's avatar Bruno Leroux Committed by GitHub

Fix TextSelectionGestureDetectorBuilder wrong cause for onDoubleTapDown (#121093)

Co-authored-by: 's avatarBruno Leroux <bruno.leroux@gmail.com>
parent 114d93f8
...@@ -2430,7 +2430,7 @@ class TextSelectionGestureDetectorBuilder { ...@@ -2430,7 +2430,7 @@ class TextSelectionGestureDetectorBuilder {
@protected @protected
void onDoubleTapDown(TapDragDownDetails details) { void onDoubleTapDown(TapDragDownDetails details) {
if (delegate.selectionEnabled) { if (delegate.selectionEnabled) {
renderEditable.selectWord(cause: SelectionChangedCause.tap); renderEditable.selectWord(cause: SelectionChangedCause.doubleTap);
if (shouldShowSelectionToolbar) { if (shouldShowSelectionToolbar) {
editableText.showToolbar(); editableText.showToolbar();
} }
......
...@@ -461,6 +461,7 @@ void main() { ...@@ -461,6 +461,7 @@ void main() {
final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable)); final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable));
expect(state.showToolbarCalled, isTrue); expect(state.showToolbarCalled, isTrue);
expect(renderEditable.selectPositionAtCalled, isTrue); expect(renderEditable.selectPositionAtCalled, isTrue);
expect(renderEditable.lastCause, SelectionChangedCause.longPress);
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('test TextSelectionGestureDetectorBuilder long press on non-Apple Platforms', (WidgetTester tester) async { testWidgets('test TextSelectionGestureDetectorBuilder long press on non-Apple Platforms', (WidgetTester tester) async {
...@@ -477,6 +478,7 @@ void main() { ...@@ -477,6 +478,7 @@ void main() {
final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable)); final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable));
expect(state.showToolbarCalled, isTrue); expect(state.showToolbarCalled, isTrue);
expect(renderEditable.selectWordCalled, isTrue); expect(renderEditable.selectWordCalled, isTrue);
expect(renderEditable.lastCause, SelectionChangedCause.longPress);
}, variant: TargetPlatformVariant.all(excluding: <TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); }, variant: TargetPlatformVariant.all(excluding: <TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('TextSelectionGestureDetectorBuilder right click Apple platforms', (WidgetTester tester) async { testWidgets('TextSelectionGestureDetectorBuilder right click Apple platforms', (WidgetTester tester) async {
...@@ -503,6 +505,7 @@ void main() { ...@@ -503,6 +505,7 @@ void main() {
await gesture.up(); await gesture.up();
await tester.pump(); await tester.pump();
expect(renderEditable.selectWordCalled, isTrue); expect(renderEditable.selectWordCalled, isTrue);
expect(renderEditable.lastCause, SelectionChangedCause.tap);
// Right clicking on a word within a selection shouldn't change the selection // Right clicking on a word within a selection shouldn't change the selection
renderEditable.selectWordCalled = false; renderEditable.selectWordCalled = false;
...@@ -589,6 +592,7 @@ void main() { ...@@ -589,6 +592,7 @@ void main() {
switch (defaultTargetPlatform) { switch (defaultTargetPlatform) {
case TargetPlatform.iOS: case TargetPlatform.iOS:
expect(renderEditable.selectWordEdgeCalled, isTrue); expect(renderEditable.selectWordEdgeCalled, isTrue);
expect(renderEditable.lastCause, SelectionChangedCause.tap);
break; break;
case TargetPlatform.macOS: case TargetPlatform.macOS:
case TargetPlatform.android: case TargetPlatform.android:
...@@ -596,6 +600,7 @@ void main() { ...@@ -596,6 +600,7 @@ void main() {
case TargetPlatform.linux: case TargetPlatform.linux:
case TargetPlatform.windows: case TargetPlatform.windows:
expect(renderEditable.selectPositionAtCalled, isTrue); expect(renderEditable.selectPositionAtCalled, isTrue);
expect(renderEditable.lastCause, SelectionChangedCause.tap);
break; break;
} }
}, variant: TargetPlatformVariant.all()); }, variant: TargetPlatformVariant.all());
...@@ -628,6 +633,7 @@ void main() { ...@@ -628,6 +633,7 @@ void main() {
case TargetPlatform.linux: case TargetPlatform.linux:
case TargetPlatform.windows: case TargetPlatform.windows:
expect(renderEditable.selectPositionAtCalled, isTrue); expect(renderEditable.selectPositionAtCalled, isTrue);
expect(renderEditable.lastCause, SelectionChangedCause.tap);
break; break;
} }
}, variant: TargetPlatformVariant.all()); }, variant: TargetPlatformVariant.all());
...@@ -670,6 +676,7 @@ void main() { ...@@ -670,6 +676,7 @@ void main() {
final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable)); final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable));
expect(state.showToolbarCalled, isTrue); expect(state.showToolbarCalled, isTrue);
expect(renderEditable.selectWordCalled, isTrue); expect(renderEditable.selectWordCalled, isTrue);
expect(renderEditable.lastCause, SelectionChangedCause.doubleTap);
}); });
testWidgets('test TextSelectionGestureDetectorBuilder forcePress enabled', (WidgetTester tester) async { testWidgets('test TextSelectionGestureDetectorBuilder forcePress enabled', (WidgetTester tester) async {
...@@ -1671,11 +1678,14 @@ class FakeRenderEditable extends RenderEditable { ...@@ -1671,11 +1678,14 @@ class FakeRenderEditable extends RenderEditable {
), ),
); );
SelectionChangedCause? lastCause;
bool selectWordsInRangeCalled = false; bool selectWordsInRangeCalled = false;
@override @override
void selectWordsInRange({ required Offset from, Offset? to, required SelectionChangedCause cause }) { void selectWordsInRange({ required Offset from, Offset? to, required SelectionChangedCause cause }) {
selectWordsInRangeCalled = true; selectWordsInRangeCalled = true;
hasFocus = true; hasFocus = true;
lastCause = cause;
} }
bool selectWordEdgeCalled = false; bool selectWordEdgeCalled = false;
...@@ -1683,6 +1693,7 @@ class FakeRenderEditable extends RenderEditable { ...@@ -1683,6 +1693,7 @@ class FakeRenderEditable extends RenderEditable {
void selectWordEdge({ required SelectionChangedCause cause }) { void selectWordEdge({ required SelectionChangedCause cause }) {
selectWordEdgeCalled = true; selectWordEdgeCalled = true;
hasFocus = true; hasFocus = true;
lastCause = cause;
} }
bool selectPositionAtCalled = false; bool selectPositionAtCalled = false;
...@@ -1694,12 +1705,14 @@ class FakeRenderEditable extends RenderEditable { ...@@ -1694,12 +1705,14 @@ class FakeRenderEditable extends RenderEditable {
selectPositionAtFrom = from; selectPositionAtFrom = from;
selectPositionAtTo = to; selectPositionAtTo = to;
hasFocus = true; hasFocus = true;
lastCause = cause;
} }
bool selectPositionCalled = false; bool selectPositionCalled = false;
@override @override
void selectPosition({ required SelectionChangedCause cause }) { void selectPosition({ required SelectionChangedCause cause }) {
selectPositionCalled = true; selectPositionCalled = true;
lastCause = cause;
return super.selectPosition(cause: cause); return super.selectPosition(cause: cause);
} }
...@@ -1708,6 +1721,7 @@ class FakeRenderEditable extends RenderEditable { ...@@ -1708,6 +1721,7 @@ class FakeRenderEditable extends RenderEditable {
void selectWord({ required SelectionChangedCause cause }) { void selectWord({ required SelectionChangedCause cause }) {
selectWordCalled = true; selectWordCalled = true;
hasFocus = true; hasFocus = true;
lastCause = cause;
} }
@override @override
......
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