-
Notifications
You must be signed in to change notification settings - Fork 29.7k
RenderParagraphs _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
RenderParagraphs _SelectableFragment.boundingBoxes should consider max line height
#155892
Conversation
a5fbb5b to
e2e7934
Compare
| 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I borrowed this from
| return endpoints[0].point + const Offset(kIsWeb? 1.0 : 0.0, -2.0); |
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.
Interesting, well I guess we should keep it around 🤷 .
32de229 to
05962ae
Compare
justinmc
left a comment
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.
LGTM 👍
| 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, well I guess we should keep it around 🤷 .
| /// An estimate of the height of a line in the text. See [TextPainter.preferredLineHeight]. | ||
| /// This does not require the layout to be updated. |
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.
Nit: Empty line of /// between these two lines, and the first line should be only 1 sentence.
chunhtai
left a comment
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.
LGTM
|
|
||
| /// An estimate of the height of a line in the text. See [TextPainter.preferredLineHeight]. | ||
| /// This does not require the layout to be updated. | ||
| double get preferredLineHeight => _textPainter.preferredLineHeight; |
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?
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!
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.
So happy to see this fixed 🎉 , thanks!
…r max line height (flutter#155892) Fixes flutter#133637 This change updates the `_SelectableFragment.boundingBoxes` logic to consider the max line height. Previously we were using boxes that were tightly bound around each glyph, so you would have to click within the bounds of the glyph for double tap to select word to work. This is different than `SelectableText` which considers the max line height, as well as the native web behavior that also considers the max line height. ## Web https://github.com/user-attachments/assets/4ce8c0ca-ec6f-4969-88b1-baa356be8278 ## Flutter SelectableText https://github.com/user-attachments/assets/54c22ad3-75d7-475b-856b-e9b2dbe09d54 ## Flutter Text widget under SelectionArea https://github.com/user-attachments/assets/27db0e2b-1d19-43cc-8ab3-16050e3a5bc7 After this change, Flutter's Text widget under a SelectionArea now matches the SelectableText and native web behavior. This change also: * Invalidates the cached bounding boxes when the paragraph layout changes. * Updates `textOffsetToPosition` to consider `preferredLineHeight`. In cases when the text wraps, it was sometimes inaccurate.
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
Manual roll Flutter from ead6b0d to 6bba08c (37 revisions) Manual roll requested by [email protected] flutter/flutter@ead6b0d...6bba08c 2024-10-01 [email protected] Feat: Add opportunity to change CupertinoTextField suffix alignment (flutter/flutter#154601) 2024-10-01 [email protected] Roll Flutter Engine from da28db8ff41d to 3fdb546bf595 (2 revisions) (flutter/flutter#155993) 2024-10-01 [email protected] Roll Flutter Engine from 6b21b796cc94 to da28db8ff41d (1 revision) (flutter/flutter#155985) 2024-10-01 [email protected] Roll Flutter Engine from 259f56c6e91b to 6b21b796cc94 (1 revision) (flutter/flutter#155983) 2024-10-01 [email protected] Roll Flutter Engine from 6ee04ed763d9 to 259f56c6e91b (1 revision) (flutter/flutter#155981) 2024-10-01 [email protected] Roll Flutter Engine from bfb6dddb2b30 to 6ee04ed763d9 (3 revisions) (flutter/flutter#155978) 2024-10-01 [email protected] Roll Flutter Engine from e61bc853acb2 to bfb6dddb2b30 (8 revisions) (flutter/flutter#155967) 2024-10-01 [email protected] Disable flaky menu test (flutter/flutter#155968) 2024-10-01 [email protected] Fix crash in Linux platform channel example. (flutter/flutter#155735) 2024-09-30 [email protected] Fix leak in input_decorator [prod-leak-fix] (flutter/flutter#155885) 2024-09-30 [email protected] Move platform specific text selection behavior out of styled TextField classes (flutter/flutter#155774) 2024-09-30 [email protected] Roll Flutter Engine from b466a0dd7834 to e61bc853acb2 (5 revisions) (flutter/flutter#155952) 2024-09-30 [email protected] `RenderParagraph`s `_SelectableFragment.boundingBoxes` should consider max line height (flutter/flutter#155892) 2024-09-30 [email protected] Roll Packages from 0321757 to 27c9853 (3 revisions) (flutter/flutter#155945) 2024-09-30 [email protected] Roll Flutter Engine from f4507e7a4beb to b466a0dd7834 (1 revision) (flutter/flutter#155944) 2024-09-30 [email protected] when `ResidentRunner.tryInitLogReader` fails, only log warning on Android (flutter/flutter#155800) 2024-09-30 [email protected] Move FlutterLogo from material to widget (flutter/flutter#155864) 2024-09-30 [email protected] fix: support android 15 16k page size for template plugin_ffi (flutter/flutter#155508) 2024-09-30 [email protected] Roll Flutter Engine from daf126b38b8f to f4507e7a4beb (1 revision) (flutter/flutter#155932) 2024-09-30 [email protected] Roll Flutter Engine from 734205fbcd62 to daf126b38b8f (1 revision) (flutter/flutter#155929) 2024-09-30 [email protected] Roll Flutter Engine from 338f09c4ea72 to 734205fbcd62 (1 revision) (flutter/flutter#155923) 2024-09-30 [email protected] Roll Flutter Engine from 897f5caffe2d to 338f09c4ea72 (2 revisions) (flutter/flutter#155917) 2024-09-30 [email protected] Roll Flutter Engine from 569abc4044b8 to 897f5caffe2d (1 revision) (flutter/flutter#155912) 2024-09-29 [email protected] Roll Flutter Engine from c4784aa7eade to 569abc4044b8 (2 revisions) (flutter/flutter#155894) 2024-09-28 [email protected] Roll Flutter Engine from ff4541712df4 to c4784aa7eade (2 revisions) (flutter/flutter#155889) 2024-09-28 [email protected] Fixes column text width calculation in CupertinoDatePicker (flutter/flutter#151128) 2024-09-28 [email protected] Roll Flutter Engine from 380fd814448c to ff4541712df4 (1 revision) (flutter/flutter#155886) 2024-09-28 [email protected] Optimize `Overlay` sample to avoid overflow (flutter/flutter#155861) 2024-09-28 [email protected] Roll Flutter Engine from f3b11bcd9c37 to 380fd814448c (1 revision) (flutter/flutter#155876) 2024-09-28 [email protected] Roll Flutter Engine from 9c8e5cb226e4 to f3b11bcd9c37 (3 revisions) (flutter/flutter#155865) 2024-09-28 [email protected] Roll Flutter Engine from f9e4ed28f103 to 9c8e5cb226e4 (1 revision) (flutter/flutter#155857) 2024-09-27 [email protected] Roll Flutter Engine from f21f2b232b8a to f9e4ed28f103 (2 revisions) (flutter/flutter#155855) 2024-09-27 [email protected] Add magnificationScale to CupertinoMagnifier for Zoom Effect (flutter/flutter#155276) 2024-09-27 [email protected] Fix typo on theme_data (flutter/flutter#155644) 2024-09-27 [email protected] Roll Flutter Engine from 7c603de2dca7 to f21f2b232b8a (6 revisions) (flutter/flutter#155843) 2024-09-27 [email protected] Turn the packages roller bot back on (flutter/flutter#155842) 2024-09-27 [email protected] Roll Packages from f38b780 to 0321757 (4 revisions) (flutter/flutter#155832) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. ...
… consider max line height (flutter/flutter#155892)
… consider max line height (flutter/flutter#155892)
Fixes #133637
This change updates the
_SelectableFragment.boundingBoxeslogic to consider the max line height. Previously we were using boxes that were tightly bound around each glyph, so you would have to click within the bounds of the glyph for double tap to select word to work. This is different thanSelectableTextwhich considers the max line height, as well as the native web behavior that also considers the max line height.Web
Screen.Recording.2024-09-28.at.6.05.47.PM.mov
Flutter SelectableText
Screen.Recording.2024-09-30.at.10.05.11.AM.mov
Flutter Text widget under SelectionArea
Screen.Recording.2024-09-30.at.10.07.32.AM.mov
After this change, Flutter's Text widget under a SelectionArea now matches the SelectableText and native web behavior.
This change also:
textOffsetToPositionto considerpreferredLineHeight. In cases when the text wraps, it was sometimes inaccurate.Pre-launch Checklist
///).