-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
SelectableText widget supports WidgetSpan #38474
Comments
_textPainter.getOffsetForCaret return Offset.zero for WidgetSpan. _textPainter.getBoxesForSelection is right for WidgetSpan, so I do a workaround for get caret position with selection boxs. but at version is high than 1.7.8 , _textPainter.getBoxesForSelection is also breaking. selection function about WidgetSpan are all breaking for https://github.com/fluttercandies/extended_text and https://github.com/fluttercandies/extended_text_field. i look forward that it will be fixed asap. |
Is there any updates? |
getPositionForOffset always return 0, after 1.7.8 |
It's 2020 April, any update on this? |
I would like to gather some feedbacks on what does it mean to If possible, please share your use cases that require widget span selection. |
We've discussed this case in #35869 (comment) . Please check it out. |
@AlexVincent525 Thank you for sharing that. That is a good example, and I will keep that in mind. The reason i am still looking for examples is that I can implement a more generic fix that can fit all use cases. |
@GaryQian When you designed the WidgetSpan did this use case of what does it mean to copy text with a widget span ever come up? Any thoughts on this issue? |
I believe we had discussed this, pur initial thoughts was to just return the toString of the widget span, which would then require the user to parse the data back into a WidgetSpan object. Since we don't really know what to expect from the nested widget, this would allow people to serialize their own widgets via toString. Was not aware of the getPositionForOffset bug, will look into it. |
I took a look at different platforms how they deal with copying none text item.
Our current API only support text format, so i think it makes sense to use string for now. I was imagining surfacing api to WidgetSpan so that developer can set the string they want when creating widgetspan instead of relying on widget.toString. |
@chunhtai Does there exist a workaround for this issue? Or is there an update? My use case is a minimal markdown viewer with special widgets for fixed-width, block quote paragraphs, and lists
|
you can use https://github.com/fluttercandies/extended_text for now, it works on 1.17.0 |
Is there any plan to support this feature? |
Updates? |
I am currently working on bringing WidgetSpan support to more areas of the framework. Currently, Editables/TextFields have the priority, but this can come after. |
SelectableText is actually built on top of EditableText internally, which means that the core WidgetSpan support added for #30688 which landed in #83537 may have also allowed SelectableText to support WidgetSpans. I will check if this is indeed true. If anyone has a particular use case, please try passing WidgetSpans to the SelectableText.rich() constructor and see if it behaves as you expect. |
I will have to remove the assert that prevents non-TextSpan spans from being passed, but otherwise, widgets are rendering as expected. Will still have to verify selection behavior. |
This sounds encouraging. Does this mean Flutter master channel as of its current state doesn't allow passing |
@daohoangson Yes, if you remove the assert, widgetspans will start rendering. My more formal PR will include tests and whatnot as well as additional validation, but if you want to try it out, removing the assert at SelectableText.dart:564 should work as a temporary way to try it. |
It works! I ran into some problem with complicated |
https://docs.google.com/document/d/1Z6_8yx7A8rHqv-K5lyTt5TPSwsKnOreJ8yztUXYXq5o/edit?usp=sharing&resourcekey=0-gmb_CPQ6mf9ODatE3JeiUg For proposals on clipboard behavior |
flutter/engine#27010 Adds support for placeholders to represent n-length codepoints in libtxt to enable intuitive selection and word bounds. |
@GaryQian, I just want to thank you for your work. I managed to update my app to have the functionality I want, I knew about this problem and that it was going to be a roadblock to achieve this sort of layout (I need it for recursive lookups as you can see), this is already excellent for my use case and I'm just thankful you got to fix this just about a week after I started working on this. Just used your fork, removed the assert and worked like a dream. My only nitpicks are that the widget spans seemingly selectable showing up as OBJ symbols in the copied text, also had trouble trying to use Thanks again and looking forward to seeing this to stable. |
@GaryQian I'm trying to implement the same functionality, but I'm getting another error after removing the assert you mentioned:
Maybe anybody faced the same problem and fixed something else in the source code to fix this? The simpliest code resulting to this error is below
I'm using flutter version 2.2.3 |
@Nickkorol can you solve this problem? If, yes then how to solve this problem. Please send this code Thanks |
It works when I check out to the Master branch... |
After flutter v2.5.0 release, it works on stable branch too (removing the assert at selectable_text.dart:582 is still required). |
Things seem to work reasonable well. Are you planning to remove the |
This comment has been minimized.
This comment has been minimized.
Let's remove the assert. Since we technically can render it with no problem, let's no longer gate it from developers. The behavior around clipboards and selection is not yet fully rich, but that is a minor problem that we can fill out in time. Behavior currently assumes a single codepoint object replacement character when converting to UTF-8 formats such as in clipboard or selections. I would not fully depend on this particular behavior yet though. Lmk if anyone has any opposing views of removing the assert and gradually adding richer support for it later. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Currently
SelectableText.rich
can only supporttextspan
. We would like to be able to support different type of inlinespan eventually asText.rich
did.This might require some discussions on how should we deal with copying or pasting a widgetspan.
The text was updated successfully, but these errors were encountered: