Skip to content
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

Fix inconsistencies when calculating start/end handle rects for selection handles #87236

Merged
merged 8 commits into from Jul 29, 2021

Conversation

Renzo-Olivares
Copy link
Contributor

@Renzo-Olivares Renzo-Olivares commented Jul 28, 2021

Description

This change updates the calculation for start/end rects for selection handles to use the current frames selection, when the current frames text is the same as the previous text, if not then we fall back to widget.renderObject.preferredLineHeight for the calculation. This is because widget.renderObject.getRectForComposingRange is only available for the previous frame, so if the current frames text and previous differ then getRectForComposingRange could fail.

In addition this change also removes the asserts for startHandleRect and endHandleRect since _TextSelectionHandleOverlayState.build checks for null handle rects.

Related Issues

Tests

Added test to make sure we are falling back to preferredLineHeight.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt.
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Jul 28, 2021
@google-cla google-cla bot added the cla: yes label Jul 28, 2021
@Renzo-Olivares Renzo-Olivares marked this pull request as ready for review July 28, 2021 23:54
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Copy link
Member

@jason-simmons jason-simmons left a comment

Choose a reason for hiding this comment

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

Confirmed that this fixes the assertions seen when testing #85789 with the SkParagraph text renderer

// for a collapsed selection, fall back to this case when that happens.
firstSelectedGraphemeExtent = 0;
lastSelectedGraphemeExtent = 0;
startHandleRect = null;
Copy link
Member

Choose a reason for hiding this comment

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

This can be removed - startHandleRect/endHandleRect will be initialized to null by default

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean I should initialize them to null by default, or is this done automatically. I tried removing this else block but got some errors saying that I cannot use the rects before they have been initialized.

Copy link
Member

Choose a reason for hiding this comment

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

The variables will be initialized to null by default if they are not final. If they are final, then they must be explicitly assigned.

Either way is fine.

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 👍 . Thanks @jason-simmons for finding this.

Is it possible to test that the asserts are no longer happening?

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.

New test looks great, thanks for adding that! 👍

@flutter-dashboard flutter-dashboard bot added the f: cupertino flutter/packages/flutter/cupertino repository label Jul 29, 2021
@fluttergithubbot fluttergithubbot merged commit 63b6197 into flutter:master Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: cupertino flutter/packages/flutter/cupertino repository framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants