Unverified Commit bccacfed authored by Ludwik Trammer's avatar Ludwik Trammer Committed by GitHub

Fix problem with right-clicking on a right-to-left selection (#80186)

parent 0f8148ec
......@@ -76,3 +76,4 @@ Pedro Massango <pedromassango.developer@gmail.com>
Hidenori Matsubayashi <Hidenori.Matsubayashi@sony.com>
Perqin Xie <perqinxie@gmail.com>
Seongyun Kim <helloworld@cau.ac.kr>
Ludwik Trammer <ludwik@gmail.com>
......@@ -963,8 +963,8 @@ class TextSelectionGestureDetectorBuilder {
renderEditable.lastSecondaryTapDownPosition!,
);
return renderEditable.selection!.base.offset <= textPosition.offset
&& renderEditable.selection!.extent.offset >= textPosition.offset;
return renderEditable.selection!.start <= textPosition.offset
&& renderEditable.selection!.end >= textPosition.offset;
}
/// Whether to show the selection toolbar.
......
......@@ -3,7 +3,7 @@
// found in the LICENSE file.
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/gestures.dart' show PointerDeviceKind;
import 'package:flutter/gestures.dart' show PointerDeviceKind, kSecondaryButton;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
......@@ -487,6 +487,49 @@ void main() {
expect(renderEditable.selectPositionAtCalled, isTrue);
});
testWidgets('TextSelectionGestureDetectorBuilder right click', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/80119
await pumpTextSelectionGestureDetectorBuilder(tester);
final FakeRenderEditable renderEditable = tester.renderObject(find.byType(FakeEditable));
renderEditable.text = const TextSpan(text: 'one two three four five six seven');
await tester.pump();
final TestGesture gesture = await tester.createGesture(
pointer: 0,
kind: PointerDeviceKind.mouse,
buttons: kSecondaryButton,
);
addTearDown(gesture.removePointer);
// Get the location of the 10th character
final Offset charLocation = renderEditable
.getLocalRectForCaret(const TextPosition(offset: 10)).center;
final Offset globalCharLocation = charLocation + tester.getTopLeft(find.byType(FakeEditable));
// Right clicking on a word should select it
await gesture.down(globalCharLocation);
await gesture.up();
await tester.pump();
expect(renderEditable.selectWordCalled, isTrue);
// Right clicking on a word within a selection shouldn't change the selection
renderEditable.selectWordCalled = false;
renderEditable.selection = const TextSelection(baseOffset: 3, extentOffset: 20);
await gesture.down(globalCharLocation);
await gesture.up();
await tester.pump();
expect(renderEditable.selectWordCalled, isFalse);
// Right clicking on a word within a reverse (right-to-left) selection shouldn't change the selection
renderEditable.selectWordCalled = false;
renderEditable.selection = const TextSelection(baseOffset: 20, extentOffset: 3);
await gesture.down(globalCharLocation);
await gesture.up();
await tester.pump();
expect(renderEditable.selectWordCalled, isFalse);
});
testWidgets('test TextSelectionGestureDetectorBuilder tap', (WidgetTester tester) async {
await pumpTextSelectionGestureDetectorBuilder(tester);
final TestGesture gesture = await tester.startGesture(
......
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