You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Text selection vertical extent should be defined per line (not per glyph) #21997
As reported by @_mono on Twitter, the Flutter text selection highlight rect should be computed at the line level as opposed to per glyph. To see this effect, paste the sequence ( ´・‿・`) into a Flutter text field and select it.
Based on the platform-specific behaviour, it looks like a bug to me. Both Android and iOS appear to use the line height.
It seems potentially useful to expose the glyph-specific metrics (e.g. if you were interested in computing text metrics of a glyph independent from its context) but in terms of selection, I'd assume we should be using line-height.
Looks like the linked commit(s) were intended to support text spans being treated as a single block for Rich text, but is now treating each glyph as a separate block.
I think I originally implemented it so that the height is the max of each line to match native/blink behavior. I believe this is mainly so that multi-line highlights do not leave awkward gaps between lines due to differing heights (as seen below).
When spans of differing heights are stacked on top of each other, they always advance enough in the y direction to accommodate the tallest span
Also, @dnfield it seems that the ( ´・‿・`) text uses characters from different sets, so they are automatically broken into different spans. it just happens that they are alternating, making it look particularly strange.
So it sounds like we're treating it as different spans because of different sets.
I think what a user would expect (and what Android/iOS do here), is that the text runs are styled the same, so they should be treated as the same height. In other words, this text run was built from a single ParagraphBuilder.addText with no intervening pushStyle or pop - or, could be generated using a single TextSpan class.
That makes sense to me, but to match native behavior (and therefore expected), I think we still should take the max of the line heights. We could also provide the glyph/span specific heights as a separate API, but not sure if that would be particularly useful.
On native text, even if you have a font size 10 on the same line as a font size 150, the bounding boxes for that line are 150 high.
Reacted by Dan Field, mono — Masayuki Ono and Chris Bracken
This issue is mostly fixed. I cannot reproduce it with Android, MacOS or iOS. But when running on Linux, there is a slight vertical offset on one of the glyphs. Updating labels to reflect the same
Activity
cbracken commentedon Sep 18, 2018
/cc @jason-simmons @garymm @xster
jason-simmons commentedon Sep 18, 2018
The engine does this intentionally (see flutter-team-archive/engine@9f8cf7e)
Is this a bug or a feature?
@Hixie
cbracken commentedon Sep 18, 2018
Based on the platform-specific behaviour, it looks like a bug to me. Both Android and iOS appear to use the line height.
It seems potentially useful to expose the glyph-specific metrics (e.g. if you were interested in computing text metrics of a glyph independent from its context) but in terms of selection, I'd assume we should be using line-height.
dnfield commentedon Sep 18, 2018
Looks like the linked commit(s) were intended to support text spans being treated as a single block for Rich text, but is now treating each glyph as a separate block.
garymm commentedon Sep 18, 2018
dnfield commentedon Sep 18, 2018
Should've been @GaryQian
GaryQian commentedon Sep 21, 2018
I think I originally implemented it so that the height is the max of each line to match native/blink behavior. I believe this is mainly so that multi-line highlights do not leave awkward gaps between lines due to differing heights (as seen below).
When spans of differing heights are stacked on top of each other, they always advance enough in the y direction to accommodate the tallest span
GaryQian commentedon Sep 21, 2018
Also, @dnfield it seems that the ( ´・‿・`) text uses characters from different sets, so they are automatically broken into different spans. it just happens that they are alternating, making it look particularly strange.
dnfield commentedon Sep 21, 2018
So it sounds like we're treating it as different spans because of different sets.
I think what a user would expect (and what Android/iOS do here), is that the text runs are styled the same, so they should be treated as the same height. In other words, this text run was built from a single
ParagraphBuilder.addTextwith no interveningpushStyleorpop- or, could be generated using a singleTextSpanclass.GaryQian commentedon Sep 21, 2018
That makes sense to me, but to match native behavior (and therefore expected), I think we still should take the max of the line heights. We could also provide the glyph/span specific heights as a separate API, but not sure if that would be particularly useful.
On native text, even if you have a font size 10 on the same line as a font size 150, the bounding boxes for that line are 150 high.
GaryQian commentedon Sep 26, 2018
flutter-team-archive/engine#6335 begins to implement a new API for more advanced GetRectsForRange, which provides the boxes for text selection.
10 remaining items
darshankawar commentedon Sep 1, 2020
Issue replicable on latest stable (1.20.2)
flutter doctor -v
code sample
exaby73 commentedon Dec 2, 2022
This issue is mostly fixed. I cannot reproduce it with Android, MacOS or iOS. But when running on Linux, there is a slight vertical offset on one of the glyphs. Updating labels to reflect the same
Linux
Android
Code Sample
reidbaker commentedon Feb 9, 2023
Gary is no longer working on flutter issues. Removing him to correctly reflect bug status.