Skip to content

Conversation

@GaryQian
Copy link
Contributor

@GaryQian GaryQian commented Apr 17, 2019

Description

Re-land attempt for #30991.

From the previous version:

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.

This version now adds the additional length to the bottom of the previously too-short caret, effectively centering the caret along the glyph. In previous versions, the additional height was added on either side, which made the caret skew too high.

This also removes the hardcoded 2px vertical offset from the Android caret, as it was an unscalable (as in, transformation scaling), especially for small font sizes where the 2px was a significant portion of the total height.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@GaryQian GaryQian added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. labels Apr 17, 2019
@GaryQian GaryQian requested a review from justinmc April 17, 2019 18:23
@GaryQian GaryQian requested a review from HansMuller April 17, 2019 18:23
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 👍

GaryQian added a commit to flutter/goldens that referenced this pull request Apr 17, 2019
@GaryQian GaryQian merged commit 3c8e3b0 into flutter:master Apr 17, 2019
@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: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextField with Chinese character.

3 participants