Skip to content

Conversation

@LongCatIsLooong
Copy link
Contributor

@LongCatIsLooong LongCatIsLooong commented Dec 26, 2023

Fixes #131435, #104594, #43400

Currently the method we use for text span hit testing TextPainter.getPositionForOffset always returns the closest TextPosition, even when the given offset is far away from the text.

The new TextPaintes method tells you the layout bounds (width = letterspacing / 2 + x_advance + letterspacing / 2, height = font ascent + font descent) of a character, the PR changes the hit testing implementation such that a TextSpan is only considered hit if the point-down event landed in one of its character's layout bounds.

Potential issues:

In theory since the text is baseline aligned, we should use the max ascent and max descent of each character to calculate the height of the text span's hit-test region, in case some characters in the span have to fall back to a different font, but that will be slower and it typically doesn't make a huge difference.
This is a breaking change.

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 this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: scrolling Viewports, list views, slivers, etc. labels Dec 26, 2023
@LongCatIsLooong
Copy link
Contributor Author

G3 migration cls have landed and this shouldn't be breaking any internal tests now.

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

@gnprice
Copy link
Member

gnprice commented Jan 4, 2024

Fixes #131435, #104594, #43400

(I just closed the latter two of these issues because they hadn't been automatically — FYI @LongCatIsLooong. GitHub's magic auto-close regexps don't recognize this sort of distributive syntax, which is why the usual convention here is like "Fixes #131435. Fixes #104594. Fixes #43400." Thanks for the fix!)

gnprice added a commit to gnprice/zulip-flutter that referenced this pull request Jan 4, 2024
By saying `tester.tapAt(find.text('hello'))`, we had been aiming
at the center of the Text widgets, and expecting that to hit the
recognizer we've put on the span, even though the widget is much
wider than the span and the latter doesn't reach the former's center.
Effectively we were relying on the presence of issue zulip#214.

But with an upstream change yesterday:
  flutter/flutter#140621
such a tap no longer hits the span.  That broke these tests.

To fix them, aim the taps near the start of the widget instead.

Fixes: zulip#475
gnprice added a commit to gnprice/zulip-flutter that referenced this pull request Jan 4, 2024
And update Flutter's supporting libraries to match.

In particular this pulls in the following upstream change:
  flutter/flutter#140621
which fixes zulip#214.

Fixes: zulip#214
chrisbobbe pushed a commit to zulip/zulip-flutter that referenced this pull request Jan 4, 2024
By saying `tester.tapAt(find.text('hello'))`, we had been aiming
at the center of the Text widgets, and expecting that to hit the
recognizer we've put on the span, even though the widget is much
wider than the span and the latter doesn't reach the former's center.
Effectively we were relying on the presence of issue #214.

But with an upstream change yesterday:
  flutter/flutter#140621
such a tap no longer hits the span.  That broke these tests.

To fix them, aim the taps near the start of the widget instead.

Fixes: #475
chrisbobbe pushed a commit to zulip/zulip-flutter that referenced this pull request Jan 4, 2024
And update Flutter's supporting libraries to match.

In particular this pulls in the following upstream change:
  flutter/flutter#140621
which fixes #214.

Fixes: #214
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 16, 2024
gnprice added a commit to gnprice/flutter_customer_testing that referenced this pull request May 22, 2024
Zulip is an open-source team chat app, with a new Flutter-based
mobile client now in beta.  This is that client's test suite.

I believe these will be the only tests currently in this registry
for an app, rather than a library.  That should naturally give them
a different mix of use cases and types of tests.

Concretely, we've seen a handful of breaking changes over the past
year that weren't caught by any of Flutter's existing test suites.
These were in text hit-testing:
  zulip/zulip-flutter@ba7a2bf
  flutter/flutter#140621

and Material menu behavior:
  zulip/zulip-flutter@38ed6c8
  flutter/flutter#130536

and SlottedContainerRenderObjectMixin gaining a type parameter:
  zulip/zulip-flutter@2f0f469
  flutter/flutter#126108

I'm not complaining, to be clear, and none of these were
particularly onerous for us to adapt to.  By registering these
tests, I'm hoping to provide feedback on future such breakages
at a point where it's actionable.

Omitted here are several tests that re-generate generated files
and check they match what's in the tree.  Those are pretty slow,
and I think they're pretty insensitive to changes in the Flutter
tree anyway; rather they depend on pigeon, json_serializable,
build_runner, and drift_dev.
gnprice added a commit to flutter/tests that referenced this pull request May 23, 2024
Zulip is an open-source team chat app, with a new Flutter-based
mobile client now in beta. This is that client's test suite.

I believe these will be the only tests currently in this registry
for an app, rather than a library. That should naturally give them
a different mix of use cases and types of tests.

Concretely, we've seen a handful of breaking changes over the past
year that weren't caught by any of Flutter's existing test suites.
These were in text hit-testing:
  zulip/zulip-flutter@ba7a2bf
  flutter/flutter#140621

and Material menu behavior:
  zulip/zulip-flutter@38ed6c8
  flutter/flutter#130536

and SlottedContainerRenderObjectMixin gaining a type parameter:
  zulip/zulip-flutter@2f0f469
  flutter/flutter#126108

I'm not complaining, to be clear, and none of these were
particularly onerous for us to adapt to. By registering these
tests, I'm hoping to provide feedback on future such breakages
at a point where it's actionable.

Omitted here are several tests that re-generate generated files
and check they match what's in the tree. Those are pretty slow,
and I think they're pretty insensitive to changes in the Flutter
tree anyway; rather they depend on pigeon, json_serializable,
build_runner, and drift_dev.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InlineText's GestureDetector is always full-width

3 participants