-
Notifications
You must be signed in to change notification settings - Fork 28.9k
RenderParagraph
s _SelectableFragment.boundingBoxes
should consider max line height
#155892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
auto-submit
merged 8 commits into
flutter:master
from
Renzo-Olivares:sa-bounding-box-fix
Sep 30, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6d1e815
boundingBoxes should take up maxHeight and should be invalidated on l…
a9a6634
Debug
685798a
Revert "Debug"
86706a4
textOffsetToPosition should consider preferredLineHeight
41606b9
update
05962ae
add test for cached bounding boxes
4fae75b
address reviewer comments
a89e9f2
make preferredLineHeight visibleForTesting only
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -16,8 +16,8 @@ import 'semantics_tester.dart'; | |||
|
||||
Offset textOffsetToPosition(RenderParagraph paragraph, int offset) { | ||||
const Rect caret = Rect.fromLTWH(0.0, 0.0, 2.0, 20.0); | ||||
final Offset localOffset = paragraph.getOffsetForCaret(TextPosition(offset: offset), caret); | ||||
return paragraph.localToGlobal(localOffset); | ||||
final Offset localOffset = paragraph.getOffsetForCaret(TextPosition(offset: offset), caret) + Offset(0.0, paragraph.preferredLineHeight); | ||||
return paragraph.localToGlobal(localOffset) + const Offset(kIsWeb ? 1.0 : 0.0, -2.0); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I borrowed this from
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting, well I guess we should keep it around 🤷 . |
||||
} | ||||
|
||||
Offset globalize(Offset point, RenderBox box) { | ||||
|
@@ -1316,6 +1316,68 @@ void main() { | |||
skip: kIsWeb, // https://github.com/flutter/flutter/issues/125582. | ||||
); | ||||
|
||||
testWidgets('RenderParagraph should invalidate cached bounding boxes', (WidgetTester tester) async { | ||||
final UniqueKey outerText = UniqueKey(); | ||||
final FocusNode focusNode = FocusNode(); | ||||
addTearDown(focusNode.dispose); | ||||
addTearDown(tester.view.reset); | ||||
|
||||
await tester.pumpWidget( | ||||
MaterialApp( | ||||
home: SelectableRegion( | ||||
focusNode: focusNode, | ||||
selectionControls: materialTextSelectionControls, | ||||
child: Scaffold( | ||||
body: Center( | ||||
child: Text( | ||||
'How are you doing today? Good, and you?', | ||||
key: outerText, | ||||
), | ||||
), | ||||
), | ||||
), | ||||
), | ||||
); | ||||
final RenderParagraph paragraph = tester.renderObject<RenderParagraph>(find.descendant(of: find.byKey(outerText), matching: find.byType(RichText)).first); | ||||
final SelectableRegionState state = | ||||
tester.state<SelectableRegionState>(find.byType(SelectableRegion)); | ||||
|
||||
// Double click to select word at position. | ||||
final TestGesture gesture = await tester.startGesture(textOffsetToPosition(paragraph, 27), kind: PointerDeviceKind.mouse); | ||||
addTearDown(gesture.removePointer); | ||||
await tester.pump(); | ||||
await gesture.up(); | ||||
await tester.pump(); | ||||
await gesture.down(textOffsetToPosition(paragraph, 27)); | ||||
await tester.pump(); | ||||
await gesture.up(); | ||||
await tester.pumpAndSettle(); | ||||
|
||||
// Should select "Good". | ||||
expect(paragraph.selections[0], const TextSelection(baseOffset: 25, extentOffset: 29)); | ||||
|
||||
// Change the size of the window. | ||||
tester.view.physicalSize = const Size(800.0, 400.0); | ||||
await tester.pumpAndSettle(); | ||||
state.clearSelection(); | ||||
await tester.pumpAndSettle(kDoubleTapTimeout); | ||||
expect(paragraph.selections.isEmpty, isTrue); | ||||
|
||||
// Double click at the same position. | ||||
await gesture.down(textOffsetToPosition(paragraph, 27)); | ||||
await tester.pump(); | ||||
await gesture.up(); | ||||
await tester.pump(); | ||||
await gesture.down(textOffsetToPosition(paragraph, 27)); | ||||
await tester.pump(); | ||||
await gesture.up(); | ||||
await tester.pumpAndSettle(); | ||||
|
||||
// Should select "Good" again. | ||||
expect(paragraph.selections.isEmpty, isFalse); | ||||
expect(paragraph.selections[0], const TextSelection(baseOffset: 25, extentOffset: 29)); | ||||
}, 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); | ||||
|
@@ -3398,12 +3460,8 @@ void main() { | |||
); | ||||
final RenderParagraph paragraph = tester.renderObject<RenderParagraph>(find.descendant(of: find.byKey(outerText), matching: find.byType(RichText)).first); | ||||
|
||||
// Adjust `textOffsetToPosition` result because it returns the wrong vertical position (wrong line). | ||||
// TODO(bleroux): Remove when https://github.com/flutter/flutter/issues/133637 is fixed. | ||||
final Offset gestureOffset = textOffsetToPosition(paragraph, 125).translate(0, 10); | ||||
|
||||
// Right click to select word at position. | ||||
final TestGesture gesture = await tester.startGesture(gestureOffset, kind: PointerDeviceKind.mouse, buttons: kSecondaryMouseButton); | ||||
final TestGesture gesture = await tester.startGesture(textOffsetToPosition(paragraph, 125), kind: PointerDeviceKind.mouse, buttons: kSecondaryMouseButton); | ||||
addTearDown(gesture.removePointer); | ||||
await tester.pump(); | ||||
await gesture.up(); | ||||
|
@@ -3448,12 +3506,8 @@ void main() { | |||
); | ||||
final RenderParagraph paragraph = tester.renderObject<RenderParagraph>(find.descendant(of: find.byKey(outerText), matching: find.byType(RichText)).first); | ||||
|
||||
// Adjust `textOffsetToPosition` result because it returns the wrong vertical position (wrong line). | ||||
// TODO(bleroux): Remove when https://github.com/flutter/flutter/issues/133637 is fixed. | ||||
final Offset gestureOffset = textOffsetToPosition(paragraph, 125).translate(0, 10); | ||||
|
||||
// Right click to select word at position. | ||||
final TestGesture gesture = await tester.startGesture(gestureOffset, kind: PointerDeviceKind.mouse, buttons: kSecondaryMouseButton); | ||||
final TestGesture gesture = await tester.startGesture(textOffsetToPosition(paragraph, 125), kind: PointerDeviceKind.mouse, buttons: kSecondaryMouseButton); | ||||
addTearDown(gesture.removePointer); | ||||
await tester.pump(); | ||||
await gesture.up(); | ||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add
@visibleForTest
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RenderEditable
has this API public, I don't have a strong preference either way, what do you think?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add it just to be conservative, we can always move to public in the future, but not backward.
and if someone does need it, we can then ask for use case and figure out whether this is really appropriate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me!