From 29618f0b0492480d531b9c7a41d2a77e76e71586 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Fri, 15 Feb 2019 10:28:21 -0800 Subject: [PATCH] Roll engine for flutter/engine#7791 - Add trailing whitespace tracking. --- bin/internal/engine.version | 2 +- .../test/material/text_field_test.dart | 89 +++++++++++++++++++ .../test/painting/text_painter_test.dart | 2 +- 3 files changed, 91 insertions(+), 2 deletions(-) diff --git a/bin/internal/engine.version b/bin/internal/engine.version index ab5b6b1532..61144926c3 100644 --- a/bin/internal/engine.version +++ b/bin/internal/engine.version @@ -1 +1 @@ -3757390fa4b00d2d261bfdf5182d2e87c9113ff9 +033f2072c315d48b4d7680d4cbbe856012b1259b diff --git a/packages/flutter/test/material/text_field_test.dart b/packages/flutter/test/material/text_field_test.dart index 37f15c90a5..3bdc359060 100644 --- a/packages/flutter/test/material/text_field_test.dart +++ b/packages/flutter/test/material/text_field_test.dart @@ -4620,4 +4620,93 @@ void main() { 'selection disabled' ]); }); + + testWidgets('Caret center position', (WidgetTester tester) async { + await tester.pumpWidget( + overlay( + child: Container( + width: 300.0, + child: const TextField( + textAlign: TextAlign.center, + decoration: null, + ), + ), + ), + ); + + final RenderEditable editable = findRenderEditable(tester); + + await tester.enterText(find.byType(TextField), 'abcd'); + await tester.pump(); + + + Offset topLeft = editable.localToGlobal( + editable.getLocalRectForCaret(const TextPosition(offset: 4)).topLeft, + ); + expect(topLeft.dx, equals(431)); + + topLeft = editable.localToGlobal( + editable.getLocalRectForCaret(const TextPosition(offset: 3)).topLeft, + ); + expect(topLeft.dx, equals(415)); + + topLeft = editable.localToGlobal( + editable.getLocalRectForCaret(const TextPosition(offset: 2)).topLeft, + ); + expect(topLeft.dx, equals(399)); + + topLeft = editable.localToGlobal( + editable.getLocalRectForCaret(const TextPosition(offset: 1)).topLeft, + ); + expect(topLeft.dx, equals(383)); + }); + + testWidgets('Caret indexes into trailing whitespace center align', (WidgetTester tester) async { + await tester.pumpWidget( + overlay( + child: Container( + width: 300.0, + child: const TextField( + textAlign: TextAlign.center, + decoration: null, + ), + ), + ), + ); + + final RenderEditable editable = findRenderEditable(tester); + + await tester.enterText(find.byType(TextField), 'abcd '); + await tester.pump(); + + Offset topLeft = editable.localToGlobal( + editable.getLocalRectForCaret(const TextPosition(offset: 7)).topLeft, + ); + expect(topLeft.dx, equals(479)); + + topLeft = editable.localToGlobal( + editable.getLocalRectForCaret(const TextPosition(offset: 8)).topLeft, + ); + expect(topLeft.dx, equals(495)); + + topLeft = editable.localToGlobal( + editable.getLocalRectForCaret(const TextPosition(offset: 4)).topLeft, + ); + expect(topLeft.dx, equals(431)); + + topLeft = editable.localToGlobal( + editable.getLocalRectForCaret(const TextPosition(offset: 3)).topLeft, + ); + expect(topLeft.dx, equals(415)); // Should be same as equivalent in 'Caret center position' + + topLeft = editable.localToGlobal( + editable.getLocalRectForCaret(const TextPosition(offset: 2)).topLeft, + ); + expect(topLeft.dx, equals(399)); // Should be same as equivalent in 'Caret center position' + + topLeft = editable.localToGlobal( + editable.getLocalRectForCaret(const TextPosition(offset: 1)).topLeft, + ); + expect(topLeft.dx, equals(383)); // Should be same as equivalent in 'Caret center position' + }); } diff --git a/packages/flutter/test/painting/text_painter_test.dart b/packages/flutter/test/painting/text_painter_test.dart index 4a9af5815b..e5f65a90ef 100644 --- a/packages/flutter/test/painting/text_painter_test.dart +++ b/packages/flutter/test/painting/text_painter_test.dart @@ -133,7 +133,7 @@ void main() { Offset caretOffset = painter.getOffsetForCaret(const ui.TextPosition(offset: 0), ui.Rect.zero); expect(caretOffset.dx, 21); caretOffset = painter.getOffsetForCaret(const ui.TextPosition(offset: text.length), ui.Rect.zero); - expect(caretOffset.dx, 399); + expect(caretOffset.dx, 441); caretOffset = painter.getOffsetForCaret(const ui.TextPosition(offset: 1), ui.Rect.zero); expect(caretOffset.dx, 35);