Skip to content

Conversation

GaryQian
Copy link
Contributor

@GaryQian GaryQian commented Oct 21, 2021

Partially resolves #38474

Manually removing this assert and using WidgetSpans seems to be stable in the wild. Since fully integrated selectable text/editable WidgetSpan support may take a significant effort but does not detract from simple use cases, we should remove this assert for now and gradually add richer support in as necessary. This unlocks WidgetSpan capability for anyone who does not need rich selection indexing and clipboards.

Tests coming soon.

@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Oct 21, 2021
@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.

@google-cla google-cla bot added the cla: yes label Oct 21, 2021
@charmoan
Copy link

Thanks

@GaryQian GaryQian requested a review from chunhtai October 21, 2021 23:43
@arianneorpilla
Copy link

arianneorpilla commented Oct 26, 2021

Very happy with this change finally being merged. Now I don't have to instruct this change made to developers working on my project. For the richer support when it comes to WidgetSpan, I suggest a String? replacement parameter so that when non-null, the object replacement character could be replaced with a String value. I'm developing an application where users can drag or tap on subtitles, and depending on which index of the character is tapped at, the callback is different.

My current implementation for the tap widget is a Wrap with GestureDetector children that have a Text child and an onTap callback for each word of the subtitle.

I swap between a SelectableText.rich for drag selection and then the tap widget described above for tap selection for different word selection modes.

If a WidgetSpan were to have a String? parameter that it takes when copied, I could use the tap widget in a SelectableText.rich for each character, through that I was hoping I could have both tap behavior and a drag behavior at the same time with the same widget with no mode switching.

I remember a document being passed around for behavior suggestions on the clipboard behavior of a WidgetSpan. In any case, this merge being made is really great and huge for anyone working on custom text selection widgets for Flutter.

@justinmc
Copy link
Contributor

@lrorpilla Thanks for the ideas here. I've created a new issue for copying WidgetSpans: #92506. This has been on my mind but I guess we didn't have an issue for it until now. We also have #23603, about rich text copy/paste, but I think that's slightly different.

clocksmith pushed a commit to clocksmith/flutter that referenced this pull request Oct 29, 2021
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: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SelectableText widget supports WidgetSpan
6 participants