Skip to content

Commit

Permalink
Relands "Changing TextPainter.getOffsetForCaret implementation to r…
Browse files Browse the repository at this point in the history
…emove the logarithmic search (#143281)" (reverted in #143801) (#143954)

The original PR was reverted because the new caret positioning callpath triggered a skparagraph assert. The assert has been removed. Relanding the PR with no changes applied.
  • Loading branch information
LongCatIsLooong authored Feb 23, 2024
1 parent c84565a commit a0a854a
Show file tree
Hide file tree
Showing 7 changed files with 900 additions and 803 deletions.
32 changes: 16 additions & 16 deletions examples/api/test/widgets/text_magnifier/text_magnifier.0_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ void main() {
const Duration durationBetweenActions = Duration(milliseconds: 20);
const String defaultText = 'I am a magnifier, fear me!';

Future<void> showMagnifier(WidgetTester tester, String characterToTapOn) async {
final Offset tapOffset = _textOffsetToPosition(tester, defaultText.indexOf(characterToTapOn));
Future<void> showMagnifier(WidgetTester tester, int textOffset) async {
assert(textOffset >= 0);
final Offset tapOffset = _textOffsetToPosition(tester, textOffset);

// Double tap 'Magnifier' word to show the selection handles.
final TestGesture testGesture = await tester.startGesture(tapOffset);
Expand All @@ -59,11 +60,11 @@ void main() {
await testGesture.up();
await tester.pumpAndSettle();

final TextSelection selection = tester
.firstWidget<TextField>(find.byType(TextField))
.controller!
.selection;
final TextEditingController controller = tester
.firstWidget<TextField>(find.byType(TextField))
.controller!;

final TextSelection selection = controller.selection;
final RenderEditable renderEditable = _findRenderEditable(tester);
final List<TextSelectionPoint> endpoints = _globalize(
renderEditable.getEndpointsForSelection(selection),
Expand All @@ -86,7 +87,7 @@ void main() {
testWidgets('should show custom magnifier on drag', (WidgetTester tester) async {
await tester.pumpWidget(const example.TextMagnifierExampleApp(text: defaultText));

await showMagnifier(tester, 'e');
await showMagnifier(tester, defaultText.indexOf('e'));
expect(find.byType(example.CustomMagnifier), findsOneWidget);

await expectLater(
Expand All @@ -96,16 +97,15 @@ void main() {
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.android }));


for (final TextDirection textDirection in TextDirection.values) {
testWidgets('should show custom magnifier in $textDirection', (WidgetTester tester) async {
final String text = textDirection == TextDirection.rtl ? 'أثارت زر' : defaultText;
final String textToTapOn = textDirection == TextDirection.rtl ? 'ت' : 'e';
testWidgets('should show custom magnifier in RTL', (WidgetTester tester) async {
const String text = 'أثارت زر';
const String textToTapOn = 'ت';

await tester.pumpWidget(example.TextMagnifierExampleApp(textDirection: textDirection, text: text));
await tester.pumpWidget(const example.TextMagnifierExampleApp(textDirection: TextDirection.rtl, text: text));

await showMagnifier(tester, textToTapOn);
await showMagnifier(tester, text.indexOf(textToTapOn));

expect(find.byType(example.CustomMagnifier), findsOneWidget);
});

expect(find.byType(example.CustomMagnifier), findsOneWidget);
});
}
}
Loading

0 comments on commit a0a854a

Please sign in to comment.