Skip to content

Conversation

@hannah-hyj
Copy link
Member

fixes: #104594

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 a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. f: scrolling Viewports, list views, slivers, etc. labels Aug 1, 2023
@flutter flutter deleted a comment from flutter-dashboard bot Aug 2, 2023
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I wonder if we should move some of the documentation from getBoxesForSelection to getBoxesForRange and add a mention to each other in the docs.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

consider using macro template to share document between these two methods

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this Center needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

add center so when add point : await gesture.addPointer(location: tester.getCenter(find.byType(Text)));

the center of the text widget is within the actual text.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain the change to this test, I don't fully understand. Thank you!

Copy link
Member Author

Choose a reason for hiding this comment

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

this is to make the text as big as the text widget, so the hittest will hit the textspan for these tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the original test no longer valid? otherwise, we should create a new test

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, the original test is no longer valid

Copy link
Contributor

Choose a reason for hiding this comment

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

weird it is declared as Object? it is probably a mistake I think

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

If we really want to be certain, this range should be coming from the span, since this is where the hittest will be sent to

Copy link
Member Author

Choose a reason for hiding this comment

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

There doesn't seem to be an existing api to get the range of a span in text painter.

I think boxes for (textPosition.offset - 1, textPosition.offset +1) should cover all cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

If there is no easy way to do that, I am fine with using textPosition.offset +-1

Also this can be
max(0, textPosition.offset - 1)

min(_textPainter.text.length, textPosition.offset + 1)

Copy link
Contributor

Choose a reason for hiding this comment

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

can you write a test that selectable textspan with recognizer will still show SystemMouseCursors.click when hover over the recognizer?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@Renzo-Olivares Renzo-Olivares left a comment

Choose a reason for hiding this comment

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

LGTM after google testing passes, it looks like some related tests are failing.

Copy link
Contributor

@chunhtai chunhtai 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 some nits

Copy link
Contributor

Choose a reason for hiding this comment

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

consider using macro template to share document between these two methods

@hannah-hyj hannah-hyj added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 3, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 3, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Aug 3, 2023

auto label is removed for flutter/flutter, pr: 131640, due to - The status or check suite ci.yaml validation has failed. Please fix the issues identified (or deflake) before re-applying this label.

@hannah-hyj hannah-hyj added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 3, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 4, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Aug 4, 2023

auto label is removed for flutter/flutter, pr: 131640, due to - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

result.add(HitTestEntry(span));
return true;
if (_positionIsWithinText(position: position, textPosition: textPosition)) {
final InlineSpan? span = _textPainter.text!.getSpanForPosition(textPosition);
Copy link
Contributor

Choose a reason for hiding this comment

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

The reason span was typed Object? was to avoid the down-casting below (i.e. span! as HitTestTarget).

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, please also add a comment on this line to explain this.

math.max(0, textPosition.offset - 1),
math.min(_textPainter.plainText.length, textPosition.offset + 1),
);
return boxes.where((ui.TextBox box) => box.toRect().contains(position)).isNotEmpty;
Copy link
Contributor

Choose a reason for hiding this comment

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

boxes.any so it stops when it finds a box.

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong Aug 4, 2023

Choose a reason for hiding this comment

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

I suspect this is going to be slow if the method gets called frequently. There's a new Skia API that will allow us to do this correctly and efficiently. Unfortunately it's not exposed in text painter yet. If this fix is not needed immediately would it be ok to wait until the new APIs are available?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not needed immediately, I can close this pr and wait for the new APIs.

Copy link
Contributor

Choose a reason for hiding this comment

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

@LongCatIsLooong What is the timeline on the Skia API? I have a need for this in Linkify (#125927). I filed #131435 and verified that this PR did fix the issue for me locally.

Even though I'm excited for this to fix my Linkify problem, it's not really super urgent. Linkify is not yet ready to merge, and merging it without this fix wouldn't even be terrible. I just want to make sure it's not going to be months or something for the Skia change.

Copy link
Contributor

Choose a reason for hiding this comment

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

The skia API is already available it just needs to be exposed (but the HTML renderer needs a separate implementation). I'll start working on that once the rounding thing is removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems 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.

SelectionArea cursor should only change when over text

5 participants