Skip to content

Commit a0a854a

Browse files
Relands "Changing TextPainter.getOffsetForCaret implementation to remove 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.
1 parent c84565a commit a0a854a

File tree

7 files changed

+900
-803
lines changed

7 files changed

+900
-803
lines changed

examples/api/test/widgets/text_magnifier/text_magnifier.0_test.dart

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ void main() {
4646
const Duration durationBetweenActions = Duration(milliseconds: 20);
4747
const String defaultText = 'I am a magnifier, fear me!';
4848

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

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

62-
final TextSelection selection = tester
63-
.firstWidget<TextField>(find.byType(TextField))
64-
.controller!
65-
.selection;
63+
final TextEditingController controller = tester
64+
.firstWidget<TextField>(find.byType(TextField))
65+
.controller!;
6666

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

89-
await showMagnifier(tester, 'e');
90+
await showMagnifier(tester, defaultText.indexOf('e'));
9091
expect(find.byType(example.CustomMagnifier), findsOneWidget);
9192

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

9899

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

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

106-
await showMagnifier(tester, textToTapOn);
106+
await showMagnifier(tester, text.indexOf(textToTapOn));
107+
108+
expect(find.byType(example.CustomMagnifier), findsOneWidget);
109+
});
107110

108-
expect(find.byType(example.CustomMagnifier), findsOneWidget);
109-
});
110-
}
111111
}

0 commit comments

Comments
 (0)