-
Notifications
You must be signed in to change notification settings - Fork 28.9k
fixed issue #159933 #172546
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
base: master
Are you sure you want to change the base?
fixed issue #159933 #172546
Conversation
It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging. 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.If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
@Renzo-Olivares From your work on rich text does it seem like this is a valid correction of getSpanForPositionVisitor? |
InlineSpan? getSpanForPositionVisitor(TextPosition position, Accumulator offset) { | ||
if (position.offset == offset.value) { | ||
// Record where this WidgetSpan begins in the flat text. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, it looks like WidgetSpan.getSpanForPositionVisitor
did not handle the upstream affinity case.
// Record where this WidgetSpan begins in the flat text. | ||
final int start = offset.value; | ||
// Advance past this one “placeholder” code unit. | ||
offset.increment(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this increment can remain in its original place (above the last null in this method).
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: these new lines look unintentional, if so let's remove them.
return null; | ||
@override | ||
InlineSpan? getSpanForPositionVisitor(TextPosition position, Accumulator offset) { | ||
final int currentOffset = offset.value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure the changes in this method are necessary (the issue seems to be fixed with only the WidgetSpan
changes). Can you explain what cases the changes in this code are trying to solve?
Hi @a5xwin, thank you for the contribution! I left a few comments. The failing This change will also need a test, maybe we can add it to test('GetSpanForPosition with WidgetSpan', () {
const TextSpan textSpan = TextSpan(
text: 'a',
children: <InlineSpan>[
TextSpan(text: 'b'),
WidgetSpan(
child: Text.rich(
TextSpan(
children: <InlineSpan>[
WidgetSpan(child: SizedBox(width: 10, height: 10)),
TextSpan(text: 'The sky is falling :)'),
],
),
),
),
TextSpan(text: 'c'),
],
);
expect(textSpan.getSpanForPosition(const TextPosition(offset: 0)).runtimeType, TextSpan);
expect(textSpan.getSpanForPosition(const TextPosition(offset: 1)).runtimeType, TextSpan);
expect(textSpan.getSpanForPosition(const TextPosition(offset: 2)).runtimeType, WidgetSpan);
expect(textSpan.getSpanForPosition(const TextPosition(offset: 3)).runtimeType, TextSpan);
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @a5xwin, could you run dart format
to correctly format all the files in this PR? And also add tests to prevent regressing these changes.
Fix TextSpan getSpanForPositionVisitor to properly handle WidgetSpan positioning
This PR fixes an issue where
TextSpan.getSpanForPositionVisitor
was not properly returningWidgetSpan
instances at the correct positions. The previous implementation had logic errors in handling text affinity and position calculations, causingWidgetSpan
elements to be incorrectly skipped or not found.Changes made:
getSpanForPositionVisitor
method to properly respect upstream affinity and handle position ranges correctlyTesting:
Fixes #159933
Pre-launch Checklist
///
).Note: CLA will be signed when prompted by the bot after PR submission.
If you need help, consider asking for advice on the #hackers-new channel on Discord.