RenderParagraph should invalidate its _SelectableFragments cached rects on window size updates (#155719)

Fixes #155143
Fixes #120578
This commit is contained in:
Renzo Olivares 2024-09-26 18:51:59 -04:00 committed by GitHub
parent 7f663fc1d8
commit 9a64920bb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 56 additions and 0 deletions

View File

@ -809,6 +809,7 @@ class RenderParagraph extends RenderBox with ContainerRenderObjectMixin<RenderBo
@override
void performLayout() {
_lastSelectableFragments?.forEach((_SelectableFragment element) => element.didChangeParagraphLayout());
final BoxConstraints constraints = this.constraints;
_placeholderDimensions = layoutInlineChildren(constraints.maxWidth, ChildLayoutHelper.layoutChild, ChildLayoutHelper.getBaseline);
_layoutTextWithConstraints(constraints);

View File

@ -1261,6 +1261,61 @@ void main() {
skip: !kIsWeb, // [intended] This test verifies web behavior.
);
testWidgets('RenderParagraph should invalidate cachedRect on window size change', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/155143.
final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);
addTearDown(tester.view.reset);
const String testString = 'How are you doing today? Good, and you?';
await tester.pumpWidget(
MaterialApp(
home: SelectableRegion(
focusNode: focusNode,
selectionControls: materialTextSelectionControls,
child: const Center(
child: Text(testString),
),
),
),
);
final RenderParagraph paragraph = tester.renderObject<RenderParagraph>(find.descendant(of: find.textContaining('How are you'), matching: find.byType(RichText)));
final TestGesture gesture = await tester.startGesture(textOffsetToPosition(paragraph, 2), kind: PointerDeviceKind.mouse);
addTearDown(gesture.removePointer);
await tester.pump();
await gesture.moveTo(textOffsetToPosition(paragraph, testString.length));
await tester.pumpAndSettle();
expect(paragraph.selections[0], const TextSelection(baseOffset: 2, extentOffset: testString.length));
await gesture.up();
await tester.pumpAndSettle();
// Change the size of the window.
tester.view.physicalSize = const Size(800.0, 400.0);
await tester.pumpAndSettle();
// Start a new drag.
await gesture.down(textOffsetToPosition(paragraph, 0));
await tester.pumpAndSettle();
await gesture.up();
await tester.pumpAndSettle(kDoubleTapTimeout);
expect(paragraph.selections.isEmpty, isFalse);
expect(paragraph.selections[0], const TextSelection.collapsed(offset: 0));
await gesture.down(textOffsetToPosition(paragraph, 2));
await tester.pumpAndSettle();
// Select to the end.
await gesture.moveTo(textOffsetToPosition(paragraph, testString.length));
await tester.pump();
expect(paragraph.selections[0], const TextSelection(baseOffset: 2, extentOffset: testString.length));
await gesture.up();
await tester.pumpAndSettle();
}, variant: TargetPlatformVariant.all(),
skip: kIsWeb, // https://github.com/flutter/flutter/issues/125582.
);
testWidgets('mouse can select single text on desktop platforms', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);