Skip to content

Use full height of the glyph for caret height on Android #30991

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
merged 5 commits into from
Apr 16, 2019

Conversation

GaryQian
Copy link
Contributor

The caret on Android has since drifted from canonical carets on Android (comparing against stock Google apps, and blank Android textfields). Flutter's carets are significantly shorter and are not centered. This problem becomes worse when mixing multiple scripts together such as english+chinese.

This PR changes the non-iOS caret (iOS caret has special handling) to instead be the full height of the glyph at the current caret position. This causes the caret to always fully cover the glyph as well as look much closer to the stock Android behavior.

To achieve this, we add getFullHeightForCaret() to TextPainter, which returns the height the caret should be if it were to fully cover the height of the glyph. To prevent multiple calculations of the boxes around the glyphs, the metrics are cached and only recalculated if the TextPosition and caret proto passed in differ.

This fixes #23934 (as well as numerous duplicates of it)

Since this changes the caret behavior, it will likely break some golden/scuba tests, although this should be a strict improvement in fidelity compared to the current behavior. I will still label it breaking change, although there are no API breakages.

@GaryQian GaryQian added a: text input Entering text in a text field or keyboard related problems c: API break Backwards-incompatible API changes a: fidelity Matching the OEM platforms better a: typography Text rendering, possibly libtxt labels Apr 12, 2019
GaryQian added a commit to flutter/goldens that referenced this pull request Apr 12, 2019
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a question about the tests.

@GaryQian
Copy link
Contributor Author

Something else we can do here is to also center the caret vertically instead of scaling off of the top left corner. This allows for adjustment of the caret height, which is not currently possible due to the origin of the caret.

@GaryQian GaryQian merged commit 96e1fc9 into flutter:master Apr 16, 2019
GaryQian added a commit that referenced this pull request Apr 16, 2019
GaryQian added a commit that referenced this pull request Apr 16, 2019
…1159)

* Revert "Use full height of the glyph for caret height on Android (#30991)"

This reverts commit 96e1fc9.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: fidelity Matching the OEM platforms better a: text input Entering text in a text field or keyboard related problems a: typography Text rendering, possibly libtxt c: API break Backwards-incompatible API changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TextField with Chinese character.
3 participants